List of usage examples for org.eclipse.jface.viewers ComboViewer ComboViewer
public ComboViewer(Composite parent, int style)
From source file:com.ebmwebsourcing.petals.services.su.wizards.pages.ChoicePage.java
License:Open Source License
@Override public void createControl(Composite parent) { // Create the composite container and define its layout final Composite container = SwtFactory.createComposite(parent); setControl(container);/*from w ww . ja v a 2 s. c o m*/ SwtFactory.applyNewGridLayout(container, 2, false, 15, 0, 0, 15); SwtFactory.applyHorizontalGridData(container); // Add a tool tip to display in case of problem this.helpTooltip = new FixedShellTooltip(getShell(), true, 90) { @Override public void populateTooltip(Composite parent) { GridLayout layout = new GridLayout(); layout.verticalSpacing = 2; parent.setLayout(layout); parent.setLayoutData(new GridData(GridData.FILL_BOTH)); parent.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); try { ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin( PetalsConstants.PETALS_COMMON_PLUGIN_ID, "icons/petals/thinking_hard.png"); if (desc != null) ChoicePage.this.helpImg = desc.createImage(); parent.setBackgroundMode(SWT.INHERIT_DEFAULT); Label imgLabel = new Label(parent, SWT.NONE); imgLabel.setImage(ChoicePage.this.helpImg); imgLabel.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true)); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.WARNING); } FontData[] fd = PlatformUtils.getModifiedFontData(getFont().getFontData(), SWT.BOLD); ChoicePage.this.boldFont = new Font(getShell().getDisplay(), fd); Label titleLabel = new Label(parent, SWT.NONE); titleLabel.setFont(ChoicePage.this.boldFont); GridData layoutData = new GridData(SWT.CENTER, SWT.DEFAULT, true, true); layoutData.verticalIndent = 5; titleLabel.setLayoutData(layoutData); titleLabel.setText("What does this error mean?"); Label l = new Label(parent, SWT.WRAP); l.setText("This wizard will generate, among other things, Maven artifacts."); layoutData = new GridData(); layoutData.verticalIndent = 8; l.setLayoutData(layoutData); RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL); rowLayout.marginLeft = 0; rowLayout.marginTop = 0; rowLayout.marginRight = 0; rowLayout.marginBottom = 0; rowLayout.spacing = 0; Composite rowComposite = new Composite(parent, SWT.NONE); rowComposite.setLayout(rowLayout); rowComposite.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true)); new Label(rowComposite, SWT.WRAP).setText("Unfortunately, there is a problem with the "); Link link = new Link(rowComposite, SWT.WRAP | SWT.NO_FOCUS); link.setText("<A>the Petals Maven preferences</A>"); new Label(rowComposite, SWT.WRAP).setText("."); new Label(parent, SWT.WRAP).setText("Please, make them correct."); link.addSelectionListener(new DefaultSelectionListener() { @Override public void widgetSelected(SelectionEvent e) { try { PreferencesUtil.createPreferenceDialogOn(new Shell(), "com.ebmwebsourcing.petals.services.prefs.maven", null, null).open(); } catch (Exception e1) { PetalsServicesPlugin.log(e1, IStatus.ERROR); } } }); } }; // Prepare the input Comparator<AbstractServiceUnitWizard> comparator = new Comparator<AbstractServiceUnitWizard>() { @Override public int compare(AbstractServiceUnitWizard o1, AbstractServiceUnitWizard o2) { String v1 = o1.getComponentVersionDescription().getComponentVersion(); String v2 = o2.getComponentVersionDescription().getComponentVersion(); return -v1.compareTo(v2); // negative so that the most recent is first } }; final Map<String, Collection<AbstractServiceUnitWizard>> componentNameToHandler = new TreeMap<String, Collection<AbstractServiceUnitWizard>>(); final Map<PetalsKeyWords, Set<String>> keywordToComponentName = new TreeMap<PetalsKeyWords, Set<String>>(); for (AbstractServiceUnitWizard handler : ExtensionManager.INSTANCE.findComponentWizards(this.petalsMode)) { for (PetalsKeyWords keyword : handler.getComponentVersionDescription().getKeyWords()) { Set<String> list = keywordToComponentName.get(keyword); if (list == null) list = new TreeSet<String>(); String componentName = handler.getComponentVersionDescription().getComponentName(); list.add(componentName); keywordToComponentName.put(keyword, list); Collection<AbstractServiceUnitWizard> handlers = componentNameToHandler.get(componentName); if (handlers == null) handlers = new TreeSet<AbstractServiceUnitWizard>(comparator); handlers.add(handler); componentNameToHandler.put(componentName, handlers); } } // Add the selection area final PhantomText searchText = new PhantomText(container, SWT.SINGLE | SWT.BORDER); searchText.setDefaultValue("Search..."); GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).span(2, 1).applyTo(searchText); final TreeViewer componentsViewer = new TreeViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); GridDataFactory.fillDefaults().span(2, 1).hint(380, 300).applyTo(componentsViewer.getTree()); componentsViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String result; if (element instanceof String) { IComponentDescription desc = componentNameToHandler.get(element).iterator().next() .getComponentVersionDescription(); String componentName = desc.getComponentName(); String componentAlias = desc.getComponentAlias(); String annotation = desc.getComponentAnnotation(); StringBuilder sb = new StringBuilder(); if (StringUtils.isEmpty(componentName)) sb.append(componentAlias); // Generic component else sb.append(componentAlias + " - " + componentName); if (!StringUtils.isEmpty(annotation)) sb.append(" ( " + annotation + " )"); result = sb.toString(); } else { result = super.getText(element); } return result; } @Override public Image getImage(Object element) { Image result = null; if (element instanceof PetalsKeyWords) { result = ChoicePage.this.keywordToImage.get(element); } else { IComponentDescription desc = componentNameToHandler.get(element).iterator().next() .getComponentVersionDescription(); result = desc.isBc() ? ChoicePage.this.bcImg : ChoicePage.this.seImg; } return result; } }); componentsViewer.setContentProvider(new DefaultTreeContentProvider() { @Override public Object[] getElements(Object inputElement) { return keywordToComponentName.keySet().toArray(); } @Override public Object[] getChildren(Object parentElement) { Object[] result; if (parentElement instanceof PetalsKeyWords) { Collection<String> componentNames = keywordToComponentName.get(parentElement); result = componentNames == null ? new Object[0] : componentNames.toArray(); } else { result = new Object[0]; } return result; } @Override public boolean hasChildren(Object element) { return element instanceof PetalsKeyWords; } }); componentsViewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { boolean result = false; String filter = searchText.getTextValue().trim().toLowerCase(); if (filter.length() == 0) result = true; else if (element instanceof PetalsKeyWords) { Set<String> names = keywordToComponentName.get(element); if (names != null) { for (String s : names) { if (select(viewer, null, s)) { result = true; break; } } } } else if (element instanceof String) result = ((String) element).toLowerCase().contains(filter); return result; } }); componentsViewer.setInput(new Object()); if (keywordToComponentName.size() > 0) componentsViewer.expandToLevel(keywordToComponentName.keySet().iterator().next(), 1); // Display the available versions new Label(container, SWT.NONE).setText("Component Version:"); final ComboViewer versionCombo = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); GridData layoutData = new GridData(); layoutData.widthHint = 130; versionCombo.getCombo().setLayoutData(layoutData); versionCombo.setContentProvider(new ArrayContentProvider()); versionCombo.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ((AbstractServiceUnitWizard) element).getComponentVersionDescription().getComponentVersion(); } }); final Label descriptionLabel = new Label(container, SWT.NONE); GridDataFactory.swtDefaults().span(2, 1).indent(0, 10).applyTo(descriptionLabel); // Selection listeners searchText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { componentsViewer.refresh(); if (searchText.getTextValue().trim().length() == 0) componentsViewer.collapseAll(); else componentsViewer.expandAll(); } }); componentsViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // Get the selection Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); Collection<?> input; if (o == null || o instanceof PetalsKeyWords) input = Collections.emptyList(); else input = componentNameToHandler.get(o); // Default selection - there is always one versionCombo.setInput(input); versionCombo.getCombo().setVisibleItemCount(input.size() > 0 ? input.size() : 1); if (!input.isEmpty()) { versionCombo.setSelection(new StructuredSelection(input.iterator().next())); versionCombo.getCombo().notifyListeners(SWT.Selection, new Event()); } else { setPageComplete(false); setSelectedNode(null); descriptionLabel.setText(""); descriptionLabel.getParent().layout(); } } }); versionCombo.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { AbstractServiceUnitWizard suWizard = (AbstractServiceUnitWizard) ((IStructuredSelection) event .getSelection()).getFirstElement(); if (suWizard == null) return; setPageComplete(true); setSelectedNode(getWizardNode(suWizard)); String desc = ChoicePage.this.petalsMode == PetalsMode.provides ? suWizard.getComponentVersionDescription().getProvideDescription() : suWizard.getComponentVersionDescription().getConsumeDescription(); descriptionLabel.setText(desc); descriptionLabel.getParent().layout(); } }); // Initialize if (PreferencesManager.isMavenTemplateConfigurationValid()) this.helpTooltip.hide(); componentsViewer.getTree().setFocus(); }
From source file:com.ecfeed.ui.dialogs.AddTestCaseDialog.java
License:Open Source License
private void createTestSuiteComposite(Composite container) { Composite composite = new Composite(container, SWT.NONE); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Label testSuiteLabel = new Label(composite, SWT.NONE); testSuiteLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); testSuiteLabel.setText("Test suite"); ComboViewer testSuiteViewer = new ComboViewer(composite, SWT.NONE); fTestSuiteCombo = testSuiteViewer.getCombo(); fTestSuiteCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fTestSuiteCombo.setItems(fMethod.getTestSuites().toArray(new String[] {})); fTestSuiteCombo.addModifyListener(new ModifyListener() { @Override//ww w. j a va2s. c o m public void modifyText(ModifyEvent e) { validateTestSuiteName(); } }); fTestSuiteCombo.setText(Constants.DEFAULT_NEW_TEST_SUITE_NAME); }
From source file:com.ecfeed.ui.dialogs.GeneratorSetupDialog.java
License:Open Source License
private void createTestSuiteComposite(Composite container) { Composite composite = new Composite(container, SWT.NONE); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Label testSuiteLabel = new Label(composite, SWT.NONE); testSuiteLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); testSuiteLabel.setText("Test suite"); ComboViewer testSuiteViewer = new ComboViewer(composite, SWT.NONE); fTestSuiteCombo = testSuiteViewer.getCombo(); fTestSuiteCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fTestSuiteCombo.setItems(fMethod.getTestSuites().toArray(new String[] {})); fTestSuiteCombo.addModifyListener(new ModifyListener() { @Override/* w ww . j a v a2 s . c om*/ public void modifyText(ModifyEvent e) { updateOkButtonAndErrorMsg(); } }); fTestSuiteCombo.setText(CommonConstants.DEFAULT_NEW_TEST_SUITE_NAME); }
From source file:com.ecfeed.ui.dialogs.GeneratorSetupDialog.java
License:Open Source License
private void createGeneratorViewer(final Composite parent) { final GeneratorFactory<ChoiceNode> generatorFactory = new GeneratorFactory<>(); ComboViewer generatorViewer = new ComboViewer(parent, SWT.READ_ONLY); fGeneratorCombo = generatorViewer.getCombo(); fGeneratorCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fGeneratorCombo.addModifyListener(new ModifyListener() { @Override// w w w. ja va 2 s. c om public void modifyText(ModifyEvent e) { try { fSelectedGenerator = generatorFactory.getGenerator(fGeneratorCombo.getText()); correctionForMethodWithOneParam(fGeneratorCombo.getText()); createParametersComposite(parent, fSelectedGenerator.parameters()); fMainContainer.layout(); } catch (GeneratorException exception) { exception.printStackTrace(); fGeneratorCombo.setText(""); } } }); if (fGeneratorFactory.availableGenerators().size() > 0) { String[] availableGenerators = generatorFactory.availableGenerators().toArray(new String[] {}); for (String generator : availableGenerators) { fGeneratorCombo.add(generator); } fGeneratorCombo.select(0); setOkButtonStatus(true); } }
From source file:com.ecfeed.ui.dialogs.SetupDialogGenerator.java
License:Open Source License
private void createTestSuiteComposite(Composite container) { Composite composite = new Composite(container, SWT.NONE); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Label testSuiteLabel = new Label(composite, SWT.NONE); testSuiteLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); testSuiteLabel.setText("Test suite"); ComboViewer testSuiteViewer = new ComboViewer(composite, SWT.NONE); fTestSuiteCombo = testSuiteViewer.getCombo(); fTestSuiteCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fTestSuiteCombo.setItems(fMethod.getTestSuites().toArray(new String[] {})); fTestSuiteCombo.addModifyListener(new ModifyListener() { @Override/*from ww w.j ava 2 s. c om*/ public void modifyText(ModifyEvent e) { updateOkButtonAndErrorMsg(); } }); fTestSuiteCombo.setText(Constants.DEFAULT_NEW_TEST_SUITE_NAME); }
From source file:com.ecfeed.ui.editor.ChoiceDetailsPage.java
License:Open Source License
private void refreshValueEditor(ChoiceNode choiceNode) { String type = fChoiceIf.getParameter().getType(); if (fValueCombo != null && fValueCombo.isDisposed() == false) { fValueCombo.dispose();//from w w w . j ava2 s .c o m } int style = SWT.DROP_DOWN; if (AbstractParameterInterface.isBoolean(type)) { style |= SWT.READ_ONLY; } fValueCombo = new ComboViewer(fAttributesComposite, style).getCombo(); fValueCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Set<String> items = new LinkedHashSet<String>(AbstractParameterInterface.getSpecialValues(type)); if (JavaUtils.isUserType(type)) { Set<String> usedValues = fChoiceIf.getParameter().getLeafChoiceValues(); usedValues.removeAll(items); items.addAll(usedValues); } items.add(fChoiceIf.getValue()); fValueCombo.setItems(items.toArray(new String[] {})); setValueComboText(choiceNode); fValueCombo.addSelectionListener(new ValueComboListener()); if (choiceNode.isAbstract()) { fValueCombo.setEnabled(false); } else { fValueCombo.setEnabled(true); } fAttributesComposite.layout(); }
From source file:com.ecfeed.ui.editor.ClassDetailsPage.java
License:Open Source License
private void initAndFillAndroidComposite(Composite composite) { composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); // row 1/*from w w w . ja va 2s .co m*/ // col 1 and 2 fRunOnAndroidCheckbox = getToolkit().createButton(composite, "Run on Android", SWT.CHECK); GridData checkboxGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); checkboxGridData.horizontalSpan = 2; fRunOnAndroidCheckbox.setLayoutData(checkboxGridData); fRunOnAndroidCheckbox.addSelectionListener(new RunOnAndroidCheckBoxAdapter()); // row 2 if (baseRunnerFieldsActive()) { // col 1 - label fAndroidBaseRunnerLabel = getToolkit().createLabel(composite, "Base runner"); // col 2 - runner combo fAndroidBaseRunnerCombo = new ComboViewer(composite, SWT.NONE).getCombo(); fAndroidBaseRunnerCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fAndroidBaseRunnerCombo.addFocusListener(new AndroidBaseRunnerComboFocusListener()); fAndroidBaseRunnerCombo.addSelectionListener(new AndroidBaseRunnerComboSelectionListener()); fillAndroidBaseRunnerCombo(); } }
From source file:com.ecfeed.ui.editor.ConstraintDetailsPage.java
License:Open Source License
private void createConstraintNameEdit(Composite parent) { Composite composite = getToolkit().createComposite(parent); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); getToolkit().createLabel(composite, "Constraint name:"); fNameCombo = new ComboViewer(composite, SWT.NONE).getCombo(); fNameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fNameCombo.addSelectionListener(new ConstraintNameListener()); }
From source file:com.ecfeed.ui.editor.TestCaseDetailsPage.java
License:Open Source License
private void createTestSuiteEdit(Composite parent) { Composite composite = getToolkit().createComposite(parent); composite.setLayout(new GridLayout(3, false)); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); getToolkit().createLabel(composite, "Test suite: "); fTestSuiteNameCombo = new ComboViewer(composite, SWT.NONE).getCombo(); fTestSuiteNameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); fTestSuiteNameCombo.addSelectionListener(new RenameTestCaseAdapter()); if (fFileInfoProvider.isProjectAvailable()) { fExecuteButton = getToolkit().createButton(composite, "Execute", SWT.NONE); fExecuteButton.addSelectionListener(new SelectionAdapter() { @Override//from w w w . j a va 2 s .c om public void widgetSelected(SelectionEvent ev) { try { fTestCaseIf.executeStaticTest(); } catch (EcException e) { ExceptionCatchDialog.open("Can not execute static tests.", e.getMessage()); } } }); } getToolkit().paintBordersFor(fTestSuiteNameCombo); }
From source file:com.foglyn.ui.FoglynRepositorySettingsPage.java
License:Open Source License
@Override protected void createAdditionalControls(Composite parent) { // Working on synchronization options Label workingOnLabel = new Label(parent, SWT.NONE); workingOnLabel.setText("'Working On' synchronization:"); workingOn = new Button(parent, SWT.CHECK); workingOn.setText("Synchronize active tasks with FogBugz"); Boolean workingOnEnabled = com.foglyn.core.Utils.isWorkingOnSynchronizationEnabled(repository); if (workingOnEnabled == null) { workingOnEnabled = FoglynUIPlugin.getDefault().isWorkingOnSynchronizationEnabled(); }/*from ww w . j a va 2s .com*/ workingOn.setSelection(workingOnEnabled.booleanValue()); // Completed case mode Label additional = new Label(parent, SWT.NONE); additional.setText("Case is marked as Complete when:"); completedModeViewer = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY); completedModeViewer.setContentProvider(new CollectionContentProvider(false)); Map<CompletedCaseMode, String> labels = new EnumMap<CompletedCaseMode, String>(CompletedCaseMode.class); labels.put(CompletedCaseMode.CLOSED, "Closed"); labels.put(CompletedCaseMode.RESOLVED_OR_CLOSED, "Closed or Resolved"); labels.put(CompletedCaseMode.SMART_RESOLVED_OR_CLOSED, "Closed if mine, Resolved or Closed otherwise"); completedModeViewer.setLabelProvider(new MapLabelProvider(labels, Collections.<Object, Image>emptyMap())); completedModeViewer.setInput(Arrays.asList(CompletedCaseMode.values())); // repository can be null -- that's OK completedModeViewer .setSelection(new StructuredSelection(com.foglyn.core.Utils.getCompletedCaseMode(repository))); completedModeViewer.getCombo().setVisibleItemCount(Constants.NUMBER_OF_ENTRIES_IN_COMBOBOX); GridDataFactory.defaultsFor(workingOnLabel).align(SWT.END, SWT.CENTER).applyTo(workingOnLabel); GridDataFactory.defaultsFor(workingOn).applyTo(workingOn); GridDataFactory.defaultsFor(additional).align(SWT.END, SWT.CENTER).applyTo(additional); GridDataFactory.defaultsFor(completedModeViewer.getControl()).applyTo(completedModeViewer.getControl()); }