List of usage examples for org.eclipse.jface.fieldassist ControlDecoration addMenuDetectListener
public void addMenuDetectListener(MenuDetectListener listener)
MenuDetectListener interface. From source file:org.eclipse.ui.examples.fieldassist.FieldAssistTestDialog.java
License:Open Source License
void createSecurityGroup(Composite parent) { Group main = new Group(parent, SWT.NONE); main.setLayoutData(new GridData(GridData.FILL_BOTH)); main.setText(TaskAssistExampleMessages.ExampleDialog_SecurityGroup); GridLayout layout = new GridLayout(); layout.numColumns = 2;//from w w w. j a v a 2 s . c o m layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); main.setLayout(layout); Label label = new Label(main, SWT.LEFT); label.setText(TaskAssistExampleMessages.ExampleDialog_UserName); // Create a field representing a user name Text text = new Text(main, SWT.BORDER); ControlDecoration dec = new ControlDecoration(text, getDecorationLocationBits()); dec.setMarginWidth(marginWidth); dec.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { MessageDialog.openInformation(getShell(), TaskAssistExampleMessages.ExampleDialog_SelectionTitle, TaskAssistExampleMessages.ExampleDialog_SelectionMessage); } public void widgetDefaultSelected(SelectionEvent e) { // Nothing on default select } }); textField = new UserField(dec, text, new TextContentAdapter()); dec.addMenuDetectListener(new MenuDetectListener() { public void menuDetected(MenuDetectEvent event) { // no quick fix if we aren't in error state. if (textField.isValid()) { return; } if (textField.quickFixMenu == null) { textField.quickFixMenu = createQuickFixMenu(textField); } textField.quickFixMenu.setLocation(event.x, event.y); textField.quickFixMenu.setVisible(true); } }); if (showRequiredFieldLabelIndicator && textField.isRequiredField()) { addRequiredFieldIndicator(label); } text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { handleModify(textField); } }); text.setText(username); installContentProposalAdapter(text, new TextContentAdapter()); text.setLayoutData(getFieldGridData()); label = new Label(main, SWT.LEFT); label.setText(TaskAssistExampleMessages.ExampleDialog_ComboUserName); // Create a combo field representing a user name Combo combo = new Combo(main, SWT.BORDER | SWT.DROP_DOWN); dec = new ControlDecoration(combo, getDecorationLocationBits()); dec.setMarginWidth(marginWidth); comboField = new UserField(dec, combo, new ComboContentAdapter()); dec.addMenuDetectListener(new MenuDetectListener() { public void menuDetected(MenuDetectEvent event) { // no quick fix if we aren't in error state. if (comboField.isValid()) { return; } if (comboField.quickFixMenu == null) { comboField.quickFixMenu = createQuickFixMenu(comboField); } comboField.quickFixMenu.setLocation(event.x, event.y); comboField.quickFixMenu.setVisible(true); } }); dec.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { MessageDialog.openInformation(getShell(), TaskAssistExampleMessages.ExampleDialog_DefaultSelectionTitle, TaskAssistExampleMessages.ExampleDialog_DefaultSelectionMessage); } public void widgetSelected(SelectionEvent e) { // Do nothing on selection } }); if (showRequiredFieldLabelIndicator) { addRequiredFieldIndicator(label); } combo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { handleModify(comboField); } }); combo.setText(username); combo.setItems(validUsers); combo.setLayoutData(getFieldGridData()); installContentProposalAdapter(combo, new ComboContentAdapter()); // Create a spinner representing a user age label = new Label(main, SWT.LEFT); label.setText(TaskAssistExampleMessages.ExampleDialog_Age); Spinner spinner = new Spinner(main, SWT.BORDER); dec = new ControlDecoration(spinner, getDecorationLocationBits()); dec.setMarginWidth(marginWidth); if (showRequiredFieldLabelIndicator) { addRequiredFieldIndicator(label); } final SmartField spinnerField = new AgeField(dec, spinner, new SpinnerContentAdapter()); spinner.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { handleModify(spinnerField); } }); spinner.setSelection(40); spinner.setLayoutData(getFieldGridData()); // This field has no decorator label = new Label(main, SWT.LEFT); label.setText(TaskAssistExampleMessages.ExampleDialog_Password); text = new Text(main, SWT.BORDER | SWT.PASSWORD); text.setText("******"); //$NON-NLS-1$ text.setLayoutData(getFieldGridData()); if (showRequiredFieldLabelIndicator) { addRequiredFieldIndicator(label); } // This tests multi-line text popup placement label = new Label(main, SWT.LEFT); label.setText(TaskAssistExampleMessages.FieldAssistTestDialog_Comments); text = new Text(main, SWT.BORDER | SWT.MULTI | SWT.WRAP); text.setText(TaskAssistExampleMessages.FieldAssistTestDialog_CommentsDefaultContent); text.setLayoutData(getMultiLineTextFieldGridData()); if (showRequiredFieldLabelIndicator) { addRequiredFieldIndicator(label); } installContentProposalAdapter(text, new TextContentAdapter()); }