Skip to content

Commit

Permalink
JBIDE-21303: Added tooltip in label
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Dec 11, 2015
1 parent 1f03e7f commit 11f1a8c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,24 @@ public abstract class AbstractTextButtonControl extends ControlBuilder<Control>

@SuppressWarnings("unchecked")
@Override
public Control build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public Text build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite parent) {
// Create the label
Label label = new Label(parent, SWT.NULL);
label.setText(getMnemonicLabel(input, true));
label.setToolTipText(input.getDescription());

final Text containerText = new Text(parent, SWT.BORDER | SWT.SINGLE);
containerText.setData(LABEL_DATA_KEY, label);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
containerText.setLayoutData(gd);

// Set Default Value
final ConverterFactory converterFactory = FurnaceService.INSTANCE
.getConverterFactory();
final ConverterFactory converterFactory = FurnaceService.INSTANCE.getConverterFactory();
if (converterFactory != null) {
Converter<Object, String> converter = (Converter<Object, String>) converterFactory
.getConverter(input.getValueType(), String.class);
String value = converter
.convert(InputComponents.getValueFor(input));
String value = converter.convert(InputComponents.getValueFor(input));
containerText.setText(value == null ? "" : value);
}
containerText.setToolTipText(input.getDescription());
Expand All @@ -70,8 +69,8 @@ public void widgetSelected(SelectionEvent e) {
browseButtonPressed(page, input, containerText);
}
});
setupAutoCompleteForText(page.getWizard().getUIContext(), input,
InputComponents.getCompleterFor(input), containerText);
setupAutoCompleteForText(page.getWizard().getUIContext(), input, InputComponents.getCompleterFor(input),
containerText);
return containerText;
}

Expand All @@ -95,12 +94,12 @@ public void setEnabled(Control control, boolean enabled) {
}
}

protected void decorateContainerText(final ForgeWizardPage page,
final InputComponent<?, ?> input, final Text containerText) {
protected void decorateContainerText(final ForgeWizardPage page, final InputComponent<?, ?> input,
final Text containerText) {

}

protected abstract void browseButtonPressed(final ForgeWizardPage page,
final InputComponent<?, ?> input, final Text containerText);
protected abstract void browseButtonPressed(final ForgeWizardPage page, final InputComponent<?, ?> input,
final Text containerText);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public class ComboControlBuilder extends ControlBuilder<Combo> {
private static final Set<Combo> COMBO_STATUS_CHANGE = Sets.getConcurrentSet();

@Override
public Combo build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public Combo build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite container) {
final CommandController controller = page.getController();
// Create the label
Label label = new Label(container, SWT.NULL);
label.setText(getMnemonicLabel(input, true));
label.setToolTipText(input.getDescription());

final Combo combo = new Combo(container, SWT.BORDER | SWT.DROP_DOWN
| SWT.READ_ONLY);
final Combo combo = new Combo(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
combo.setData(LABEL_DATA_KEY, label);
combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
combo.addModifyListener(new ModifyListener() {
@Override
Expand Down Expand Up @@ -103,10 +103,7 @@ public void updateState(Combo combo, InputComponent<?, ?> input) {
}

private Converter<Object, String> getConverter(UISelectOne<Object> selectOne) {
return (Converter<Object, String>) InputComponents
.getItemLabelConverter(
FurnaceService.INSTANCE.getConverterFactory(),
selectOne);
return InputComponents.getItemLabelConverter(FurnaceService.INSTANCE.getConverterFactory(), selectOne);
}

@SuppressWarnings("unchecked")
Expand All @@ -118,8 +115,7 @@ private void updateValues(Combo combo, InputComponent<?, ?> input) {

private void updateDefaultValue(Combo combo, UISelectOne<Object> selectOne) {
Converter<Object, String> converter = getConverter(selectOne);
String value = converter
.convert(InputComponents.getValueFor(selectOne));
String value = converter.convert(InputComponents.getValueFor(selectOne));
if (value == null) {
combo.setText("");
} else if (!value.equals(combo.getText())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
public abstract class ControlBuilder<CONTROL extends Control> {

protected static final String LABEL_DATA_KEY = "forge.label";
private static final String NOTE_DATA_KEY = "forge.note";

/**
Expand All @@ -52,8 +53,7 @@ public abstract class ControlBuilder<CONTROL extends Control> {
* the container this control will be placed on
* @return
*/
public abstract CONTROL build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public abstract CONTROL build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite container);

/**
Expand Down Expand Up @@ -94,13 +94,11 @@ public boolean handles(InputComponent<?, ?> input) {

if (handles) {
String inputTypeHint = InputComponents.getInputType(input);
if (inputTypeHint != null
&& !inputTypeHint.equals(InputType.DEFAULT)) {
if (inputTypeHint != null && !inputTypeHint.equals(InputType.DEFAULT)) {
handles = inputTypeHint.equals(getSupportedInputType());
} else {
// Fallback to standard type
handles = getProducedType().isAssignableFrom(
input.getValueType());
handles = getProducedType().isAssignableFrom(input.getValueType());
}
}

Expand Down Expand Up @@ -129,33 +127,27 @@ public Control[] getModifiableControlsFor(CONTROL control) {
}
}

protected ContentProposalAdapter setupAutoCompleteForText(
UIContextImpl context, InputComponent<?, ?> input,
protected ContentProposalAdapter setupAutoCompleteForText(UIContextImpl context, InputComponent<?, ?> input,
UICompleter<?> completer, Text text) {
ContentProposalAdapter result = null;
if (completer != null) {
ControlDecoration dec = new ControlDecoration(text, SWT.TOP
| SWT.LEFT);
ControlDecoration dec = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
// Add lightbulb
FieldDecoration completerIndicator = FieldDecorationRegistry
.getDefault().getFieldDecoration(
FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
FieldDecoration completerIndicator = FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
dec.setImage(completerIndicator.getImage());
dec.setDescriptionText(completerIndicator.getDescription());

// Register auto-complete
KeyStroke activationKeyStroke = KeyStroke.getInstance(SWT.CONTROL,
SWT.SPACE);
KeyStroke activationKeyStroke = KeyStroke.getInstance(SWT.CONTROL, SWT.SPACE);
result = new ContentProposalAdapter(text, new TextContentAdapter(),
new InputComponentProposalProvider(context, input,
completer), activationKeyStroke, null);
new InputComponentProposalProvider(context, input, completer), activationKeyStroke, null);
result.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}
return result;
}

public void setupNote(Composite parent, Control control,
InputComponent<?, ?> input) {
public void setupNote(Composite parent, Control control, InputComponent<?, ?> input) {
// Add a placeholder
Label placeholder = new Label(parent, SWT.NONE);
GridData layoutData = new GridData();
Expand All @@ -176,8 +168,7 @@ public void setupNote(Composite parent, Control control,
}
}

protected String getMnemonicLabel(InputComponent<?, ?> input,
boolean addColon) {
protected String getMnemonicLabel(InputComponent<?, ?> input, boolean addColon) {
String label = InputComponents.getLabelFor(input, addColon);
char shortName = input.getShortName();
if (shortName != InputComponents.DEFAULT_SHORT_NAME) {
Expand All @@ -189,6 +180,7 @@ protected String getMnemonicLabel(InputComponent<?, ?> input,
public void updateState(CONTROL control, InputComponent<?, ?> input) {
setEnabled(control, input.isEnabled());
setNote(control, input.getNote());
setLabelTooltip(control, input.getDescription());
}

protected void setNote(CONTROL control, String note) {
Expand All @@ -207,6 +199,13 @@ protected void setNote(CONTROL control, String note) {
}
}

protected void setLabelTooltip(CONTROL control, String tooltip) {
Label label = (Label) control.getData(LABEL_DATA_KEY);
if (label != null) {
label.setToolTipText(tooltip);
}
}

protected ConverterFactory getConverterFactory() {
return FurnaceService.INSTANCE.getConverterFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ public class RadioControlBuilder extends ControlBuilder<Control> {

@Override
@SuppressWarnings({ "unchecked" })
public Control build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public Control build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite parent) {
// Create the label
Label label = new Label(parent, SWT.NULL);
label.setText(getMnemonicLabel(input, true));
label.setToolTipText(input.getDescription());

Composite container = new Composite(parent, SWT.NULL);
container.setData(LABEL_DATA_KEY, label);
container.setLayout(new RowLayout());
container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

final ConverterFactory converterFactory = FurnaceService.INSTANCE
.getConverterFactory();
final ConverterFactory converterFactory = FurnaceService.INSTANCE.getConverterFactory();
UISelectOne<Object> selectOne = (UISelectOne<Object>) input;
Converter<Object, String> itemLabelConverter = (Converter<Object, String>) InputComponents
.getItemLabelConverter(converterFactory, selectOne);
Converter<Object, String> itemLabelConverter = InputComponents.getItemLabelConverter(converterFactory,
selectOne);
Object originalValue = InputComponents.getValueFor(input);
Iterable<Object> valueChoices = selectOne.getValueChoices();
if (valueChoices != null) {
Expand All @@ -60,10 +60,8 @@ public Control build(final ForgeWizardPage page,
@Override
public void widgetSelected(SelectionEvent e) {
if (button.getSelection()) {
final CommandController controller = page
.getController();
controller.setValueFor(inputName,
Proxies.unwrap(choice));
final CommandController controller = page.getController();
controller.setValueFor(inputName, Proxies.unwrap(choice));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,26 @@ public class SpinnerControlBuilder extends ControlBuilder<Spinner> {

@SuppressWarnings("unchecked")
@Override
public Spinner build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public Spinner build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite container) {
// Create the label
Label label = new Label(container, SWT.NULL);
label.setText(getMnemonicLabel(input, true));
label.setToolTipText(input.getDescription());

final Spinner txt = new Spinner(container, SWT.BORDER);
txt.setData(LABEL_DATA_KEY, label);
// TODO: Ranges may be configurable in the future
txt.setMinimum(Integer.MIN_VALUE);
txt.setMaximum(Integer.MAX_VALUE);
txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
txt.setToolTipText(input.getDescription());
// Set Default Value
final ConverterFactory converterFactory = FurnaceService.INSTANCE
.getConverterFactory();
final ConverterFactory converterFactory = FurnaceService.INSTANCE.getConverterFactory();
if (converterFactory != null) {
Converter<Object, Integer> converter = (Converter<Object, Integer>) converterFactory
.getConverter(input.getValueType(), Integer.class);
Integer value = converter.convert(InputComponents
.getValueFor(input));
Integer value = converter.convert(InputComponents.getValueFor(input));
txt.setSelection(value == null ? 0 : value);
}
txt.addModifyListener(new ModifyListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,25 @@
public class TextAreaBoxControlBuilder extends ControlBuilder<Text> {

@Override
public Text build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public Text build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite container) {
// Create the label
Label label = new Label(container, SWT.NULL);
label.setText(getMnemonicLabel(input, true));
label.setToolTipText(input.getDescription());

final Text txt = new Text(container, SWT.MULTI | SWT.BORDER | SWT.WRAP
| SWT.V_SCROLL);
final Text txt = new Text(container, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
txt.setData(LABEL_DATA_KEY, label);
GridData textareaLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
textareaLayoutData.heightHint = 100;
txt.setLayoutData(textareaLayoutData);
txt.setToolTipText(input.getDescription());
// Set Default Value
final ConverterFactory converterFactory = FurnaceService.INSTANCE
.getConverterFactory();
final ConverterFactory converterFactory = FurnaceService.INSTANCE.getConverterFactory();
if (converterFactory != null) {
Converter<Object, String> converter = (Converter<Object, String>) converterFactory
.getConverter(input.getValueType(), String.class);
String value = converter
.convert(InputComponents.getValueFor(input));
String value = converter.convert(InputComponents.getValueFor(input));
txt.setText(value == null ? "" : value);
}

Expand All @@ -64,8 +62,7 @@ public void modifyText(ModifyEvent e) {
}
}
});
setupAutoCompleteForText(page.getWizard().getUIContext(), input,
InputComponents.getCompleterFor(input), txt);
setupAutoCompleteForText(page.getWizard().getUIContext(), input, InputComponents.getCompleterFor(input), txt);

// skip the third column
Label dummy = new Label(container, SWT.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,23 @@
public class TextBoxControlBuilder extends ControlBuilder<Text> {

@Override
public Text build(final ForgeWizardPage page,
final InputComponent<?, ?> input, final String inputName,
public Text build(final ForgeWizardPage page, final InputComponent<?, ?> input, final String inputName,
final Composite container) {
// Create the label
Label label = new Label(container, SWT.NULL);
final Label label = new Label(container, SWT.NULL);
label.setText(getMnemonicLabel(input, true));
label.setToolTipText(input.getDescription());

final Text txt = new Text(container, SWT.BORDER | SWT.SINGLE);
txt.setData(LABEL_DATA_KEY, label);
txt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
txt.setToolTipText(input.getDescription());
// Set Default Value
final ConverterFactory converterFactory = FurnaceService.INSTANCE
.getConverterFactory();
final ConverterFactory converterFactory = FurnaceService.INSTANCE.getConverterFactory();
if (converterFactory != null) {
Converter<Object, String> converter = (Converter<Object, String>) converterFactory
.getConverter(input.getValueType(), String.class);
String value = converter
.convert(InputComponents.getValueFor(input));
String value = converter.convert(InputComponents.getValueFor(input));
txt.setText(value == null ? "" : value);
}

Expand All @@ -61,8 +60,7 @@ public void modifyText(ModifyEvent e) {
}
}
});
setupAutoCompleteForText(page.getWizard().getUIContext(), input,
InputComponents.getCompleterFor(input), txt);
setupAutoCompleteForText(page.getWizard().getUIContext(), input, InputComponents.getCompleterFor(input), txt);

// skip the third column
Label dummy = new Label(container, SWT.NONE);
Expand Down
Loading

0 comments on commit 11f1a8c

Please sign in to comment.