List of usage examples for org.eclipse.jface.viewers ComboViewer setLabelProvider
@Override public void setLabelProvider(IBaseLabelProvider labelProvider)
Viewer
framework method ensures that the given label provider is an instance of ILabelProvider
. From source file:com.contrastsecurity.ide.eclipse.ui.internal.views.FilterDialog.java
License:Open Source License
private ComboViewer createContrastComboViewer(final Composite composite) { ComboViewer comboViewer = new ComboViewer(composite, SWT.READ_ONLY); comboViewer.getControl().setFont(composite.getFont()); comboViewer.setLabelProvider(new ContrastLabelProvider()); comboViewer.setContentProvider(new ArrayContentProvider()); return comboViewer; }
From source file:com.contrastsecurity.ide.eclipse.ui.util.UIElementUtils.java
License:Open Source License
public static ComboViewer createComboViewer(Composite composite) { ComboViewer comboViewer = new ComboViewer(composite, SWT.READ_ONLY); comboViewer.getControl().setFont(composite.getFont()); comboViewer.setLabelProvider(new LabelProvider()); comboViewer.setContentProvider(new ArrayContentProvider()); return comboViewer; }
From source file:com.ebmwebsoucing.petals.repositories.explorer.wizards.QueryApiBeanDefinitionDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite bigContainer = new Composite((Composite) super.createDialogArea(parent), SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 10;/*from w ww . j av a 2 s . c o m*/ bigContainer.setLayout(layout); bigContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); // Add the API field new Label(bigContainer, SWT.NONE).setText("Query API:"); ComboViewer viewer = new ComboViewer(bigContainer, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN); viewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String result = ""; if (element instanceof RepositoryQueryApi) result = ((RepositoryQueryApi) element).toString(); return result; } }); viewer.setInput(RepositoryQueryApi.values()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty()) { QueryApiBeanDefinitionDialog.this.api = (RepositoryQueryApi) ((IStructuredSelection) event .getSelection()).getFirstElement(); validate(); } } }); // Add the URL field new Label(bigContainer, SWT.NONE).setText("Query URI:"); Text urlText = new Text(bigContainer, SWT.SINGLE | SWT.BORDER); urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); urlText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { QueryApiBeanDefinitionDialog.this.uriAsString = ((Text) e.widget).getText(); validate(); } }); getShell().setText("New Query API"); setTitle("Query API"); setMessage("Associate a new Query API with this repository."); return bigContainer; }
From source file:com.ebmwebsourcing.petals.common.croquis.internal.provisional.CroquisNewWizardPage.java
License:Open Source License
public void createControl(Composite parent) { // The top composite Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, true); layout.horizontalSpacing = 8;/*w ww. j a va2 s.co m*/ container.setLayout(layout); container.setLayoutData(new GridData(GridData.FILL_BOTH)); setControl(container); // Update the page settings setTitle("New Petals Croquis"); getShell().setText("New Petals Croquis"); setDescription("Create a new croquis for Petals ESB."); // The left part final Composite leftContainer = new Composite(container, SWT.NONE); layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginTop = 2; leftContainer.setLayout(layout); leftContainer.setLayoutData(new GridData(GridData.FILL_BOTH)); final Label l = new Label(leftContainer, SWT.NONE); l.setText("Croquis Type:"); l.setToolTipText("Select the kind of croquis to create"); final ComboViewer croquisViewer = new ComboViewer(leftContainer, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN); croquisViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); croquisViewer.setContentProvider(new ArrayContentProvider()); croquisViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return element instanceof String ? (String) element : ((ICroquisExtension) element).getTitle(); } }); // The right part Composite rightContainer = new Composite(container, SWT.BORDER); rightContainer.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); layout = new GridLayout(); layout.marginWidth = 12; layout.marginHeight = 12; rightContainer.setLayout(layout); rightContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Label screenshotLabel = new Label(rightContainer, SWT.NONE); screenshotLabel.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); final Label descriptionLabel = new Label(rightContainer, SWT.NONE); GridData layoutData = new GridData(SWT.CENTER, SWT.DEFAULT, true, false); layoutData.verticalIndent = 7; descriptionLabel.setLayoutData(layoutData); descriptionLabel.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); // The selection change listener croquisViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (!(o instanceof ICroquisExtension)) return; if (o.equals(CroquisNewWizardPage.this.selectedExtension)) return; CroquisNewWizardPage.this.selectedExtension = (ICroquisExtension) o; String text = ((ICroquisExtension) o).getDescription(); descriptionLabel.setText(text); ImageDescriptor desc = ((ICroquisExtension) o).getScreenshot(); if (CroquisNewWizardPage.this.currentImage != null && CroquisNewWizardPage.this.currentImage != CroquisNewWizardPage.this.defaultImage) { CroquisNewWizardPage.this.currentImage.dispose(); CroquisNewWizardPage.this.currentImage = null; } if (desc != null) { try { CroquisNewWizardPage.this.currentImage = desc.createImage(); } catch (Exception e) { PetalsCommonPlugin.log(e, IStatus.ERROR); } } else { CroquisNewWizardPage.this.currentImage = CroquisNewWizardPage.this.defaultImage; } screenshotLabel.setImage(CroquisNewWizardPage.this.currentImage); screenshotLabel.getParent().layout(); for (Control c : leftContainer.getChildren()) { if (c != l && c != croquisViewer.getCombo()) c.dispose(); } ((ICroquisExtension) o).createControl(leftContainer, CroquisNewWizardPage.this); leftContainer.layout(); } }); // Initialize the rest List<ICroquisExtension> ext = CroquisContributionManager.INSTANCE.getCroquisData(); if (ext.size() > 0) { croquisViewer.setInput(ext); croquisViewer.getCombo().select(0); croquisViewer.getCombo().notifyListeners(SWT.Selection, new Event()); } else { croquisViewer.setInput("-- No Croquis Available --"); } }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.emf.EObjectUIHelper.java
License:Open Source License
/** * Produces the widgets./*from w w w . j av a 2 s. c o m*/ * @param toolkit * @param parent * @param featuresToLabels * @return */ private static List<EntryDescription> produceWidgets(FormToolkit toolkit, Color labelColor, Composite parent, Map<EStructuralFeature, String> featuresToLabels) { List<EntryDescription> entries = new ArrayList<EntryDescription>(); for (Map.Entry<EStructuralFeature, String> entry : featuresToLabels.entrySet()) { Object widget = null; EAttribute attr = (EAttribute) entry.getKey(); String label = entry.getValue(); // The label // TODO leverage ExtendedMetaData.INSTANCE for tool tip and label if (label == null) { label = StringUtils.camelCaseToHuman(attr.getName()); label = StringUtils.capitalize(label); if (attr.getLowerBound() > 0) label += " *"; label += ":"; } Label labelWidget = toolkit.createLabel(parent, label); labelWidget.setBackground(parent.getBackground()); if (labelColor != null) labelWidget.setForeground(labelColor); // The widget Class<?> instanceClass = attr.getEType().getInstanceClass(); if (instanceClass.equals(String.class)) { String lowered = label.toLowerCase(); if (lowered.contains("password") || lowered.contains("passphrase")) widget = SwtFactory.createPasswordField(parent, false).getText(); else if (lowered.contains("folder") || lowered.contains("directory")) widget = SwtFactory.createDirectoryBrowser(parent).getText(); else widget = toolkit.createText(parent, "", SWT.BORDER); ((Text) widget).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } else if (instanceClass.equals(Integer.class) || instanceClass.equals(int.class)) { widget = new Spinner(parent, SWT.BORDER); GridDataFactory.swtDefaults().hint(100, SWT.DEFAULT).minSize(100, SWT.DEFAULT) .applyTo((Spinner) widget); ((Spinner) widget).setMaximum(Integer.MAX_VALUE); } else if (instanceClass.isEnum()) { widget = new ComboViewer(parent, SWT.READ_ONLY | SWT.FLAT); ComboViewer viewer = (ComboViewer) widget; viewer.setContentProvider(new EEnumLiteralsProvider()); viewer.setLabelProvider(new EEnumNameLabelProvider()); viewer.setInput(attr.getEType()); viewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } else if (instanceClass.equals(Boolean.class) || instanceClass.equals(boolean.class)) { widget = new ComboViewer(parent, SWT.READ_ONLY | SWT.FLAT); ComboViewer viewer = (ComboViewer) widget; viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider()); viewer.setInput(new Boolean[] { Boolean.TRUE, Boolean.FALSE }); Combo combo = ((ComboViewer) widget).getCombo(); GridDataFactory.swtDefaults().hint(100, SWT.DEFAULT).minSize(100, SWT.DEFAULT).applyTo(combo); } if (widget != null) entries.add(new EntryDescription(widget, attr)); } return entries; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.SwtFactory.java
License:Open Source License
/** * Creates a combo viewer with a default label provider and an array content provider. * @param parent the parent/*from ww w. ja v a 2 s .c o m*/ * @param useWholeSpace true to use the whole space horizontally * @param values the values to put in the viewer * @return the viewer */ public static ComboViewer createDefaultComboViewer(Composite parent, boolean useWholeSpace, boolean readOnly, Object[] values) { int style = SWT.SINGLE | SWT.BORDER; if (readOnly) style |= SWT.READ_ONLY; final ComboViewer viewer = new ComboViewer(parent, style); if (useWholeSpace) viewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider()); viewer.setInput(values); return viewer; }
From source file:com.ebmwebsourcing.petals.components.wizards.ComponentNewWizardPage.java
License:Open Source License
/** * @see IDialogPage#createControl(Composite) *///from www .j a v a2 s . com @Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayoutFactory.swtDefaults().numColumns(2).extendedMargins(15, 15, 20, 0).spacing(15, 9) .applyTo(container); container.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false)); // Component Fields new Label(container, SWT.NONE).setText("Component &type:"); final Combo componentTypeCombo = new Combo(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); componentTypeCombo.add("Binding Component"); componentTypeCombo.add("Service Engine"); componentTypeCombo.select(this.bc ? 0 : 1); componentTypeCombo.addSelectionListener(new DefaultSelectionListener() { @Override public void widgetSelected(SelectionEvent e) { int index = ((Combo) e.widget).getSelectionIndex(); ComponentNewWizardPage.this.bc = index == 0; // Validation is implicit, called by the name text } }); new Label(container, SWT.NONE).setText("Component &name:"); final Text componentNameText = new Text(container, SWT.BORDER | SWT.SINGLE); componentNameText.setText(this.name); componentNameText.setSelection(ComponentNewWizardPage.SELECTION_OFFSET, this.name.length()); componentNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(container, SWT.NONE).setText("&Group ID:"); final Text componentGroupIdText = new Text(container, SWT.BORDER | SWT.SINGLE); componentGroupIdText.setText(this.groupId); componentGroupIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); componentGroupIdText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { ComponentNewWizardPage.this.groupId = ((Text) e.widget).getText(); validate(); } }); new Label(container, SWT.NONE).setText("Java Root Package:"); final Text rootPckgText = new Text(container, SWT.BORDER | SWT.SINGLE); rootPckgText.setText(this.rootPackage); rootPckgText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); rootPckgText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { ComponentNewWizardPage.this.rootPackage = ((Text) e.widget).getText(); validate(); } }); new Label(container, SWT.NONE).setText("&Petals Version:"); ComboViewer containerViewer = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); containerViewer.setLabelProvider(new LabelProvider()); containerViewer.setContentProvider(new ArrayContentProvider()); containerViewer.setInput(PetalsContainerVersion.values()); containerViewer.setSelection(new StructuredSelection(this.petalsContainerVersion)); containerViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ComponentNewWizardPage.this.petalsContainerVersion = (PetalsContainerVersion) ((IStructuredSelection) event .getSelection()).getFirstElement(); validate(); } }); // Project location final Button useDefaultLocButton = new Button(container, SWT.CHECK); useDefaultLocButton.setText("Create the project in the default location"); GridData layoutData = new GridData(); layoutData.horizontalSpan = 2; layoutData.verticalIndent = 17; useDefaultLocButton.setLayoutData(layoutData); Composite locContainer = new Composite(container, SWT.NONE); GridLayoutFactory.swtDefaults().numColumns(3).margins(0, 0).applyTo(locContainer); layoutData = new GridData(GridData.FILL_HORIZONTAL); layoutData.horizontalSpan = 2; locContainer.setLayoutData(layoutData); final Label locLabel = new Label(locContainer, SWT.NONE); locLabel.setText("Project location:"); final Text projectLocationText = new Text(locContainer, SWT.SINGLE | SWT.BORDER); projectLocationText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); projectLocationText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); projectLocationText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { ComponentNewWizardPage.this.location = ((Text) e.widget).getText().trim(); validate(); } }); final Button browseButton = new Button(locContainer, SWT.PUSH); browseButton.setText("Browse..."); browseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String location = new DirectoryDialog(getShell()).open(); if (location != null) projectLocationText.setText(location); } }); useDefaultLocButton.setSelection(this.isAtDefaultLocation); useDefaultLocButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ComponentNewWizardPage.this.isAtDefaultLocation = useDefaultLocButton.getSelection(); boolean use = !ComponentNewWizardPage.this.isAtDefaultLocation; locLabel.setEnabled(use); projectLocationText.setEnabled(use); browseButton.setEnabled(use); projectLocationText.setFocus(); validate(); } }); // Listeners componentTypeCombo.addSelectionListener(new DefaultSelectionListener() { @Override public void widgetSelected(SelectionEvent e) { int selection = ((Combo) e.widget).getSelectionIndex(); String componentName = componentNameText.getText().substring(10); String newName = "petals-" + (selection == 0 ? "bc-" : "se-") + componentName; componentNameText.setText(newName); componentNameText.setSelection(newName.length()); } }); componentNameText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { int selection = componentTypeCombo.getSelectionIndex(); String componentName = componentNameText.getText().substring(10); String newGroupId = componentGroupIdText.getText(); if (newGroupId.startsWith("org.ow2.petals.")) newGroupId = "org.ow2.petals." + (selection == 0 ? "bc" : "se") + "." + componentName; ComponentNewWizardPage.this.name = ((Text) e.widget).getText().trim(); componentGroupIdText.setText(newGroupId); // Validation is implicit, called by the group ID text } }); componentNameText.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { componentNameText.setSelection(ComponentNewWizardPage.SELECTION_OFFSET, ComponentNewWizardPage.this.name.length()); } }); // Last steps in the UI definition useDefaultLocButton.notifyListeners(SWT.Selection, new Event()); componentTypeCombo.setFocus(); setControl(container); }
From source file:com.ebmwebsourcing.petals.components.wizards.SharedLibraryNewWizardPage.java
License:Open Source License
/** * @see IDialogPage#createControl(Composite) *///w w w . jav a 2 s . co m @Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginLeft = 15; layout.marginRight = 15; layout.marginTop = 20; layout.horizontalSpacing = 15; layout.verticalSpacing = 9; container.setLayout(layout); container.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false)); // Name new Label(container, SWT.NONE).setText("Shared-Library &name:"); final Text slNameText = new Text(container, SWT.BORDER | SWT.SINGLE); slNameText.setText(this.name); slNameText.setSelection(SharedLibraryNewWizardPage.SELECTION_OFFSET, this.name.length()); slNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); slNameText.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { String componentName = slNameText.getText(); slNameText.setSelection(SharedLibraryNewWizardPage.SELECTION_OFFSET, componentName.length()); } }); // Group ID new Label(container, SWT.NONE).setText("&Group ID:"); final Text slGroupIdText = new Text(container, SWT.BORDER | SWT.SINGLE); slGroupIdText.setText(this.groupId); slGroupIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); slGroupIdText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { SharedLibraryNewWizardPage.this.groupId = slGroupIdText.getText().trim(); validate(); } }); // Petals version new Label(container, SWT.NONE).setText("&Petals Version:"); ComboViewer containerViewer = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); containerViewer.setLabelProvider(new LabelProvider()); containerViewer.setContentProvider(new ArrayContentProvider()); containerViewer.setInput(PetalsContainerVersion.values()); containerViewer.setSelection(new StructuredSelection(this.petalsContainerVersion)); containerViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { SharedLibraryNewWizardPage.this.petalsContainerVersion = (PetalsContainerVersion) ((IStructuredSelection) event .getSelection()).getFirstElement(); validate(); } }); // Project location final Button useDefaultLocButton = new Button(container, SWT.CHECK); useDefaultLocButton.setText("Create the project in the default location"); GridData layoutData = new GridData(); layoutData.horizontalSpan = 2; layoutData.verticalIndent = 17; useDefaultLocButton.setLayoutData(layoutData); Composite locContainer = new Composite(container, SWT.NONE); layout = new GridLayout(3, false); layout.marginHeight = layout.marginWidth = 0; locContainer.setLayout(layout); layoutData = new GridData(GridData.FILL_HORIZONTAL); layoutData.horizontalSpan = 2; locContainer.setLayoutData(layoutData); final Label locLabel = new Label(locContainer, SWT.NONE); locLabel.setText("Project location:"); final Text projectLocationText = new Text(locContainer, SWT.SINGLE | SWT.BORDER); projectLocationText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); projectLocationText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); projectLocationText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { SharedLibraryNewWizardPage.this.location = ((Text) e.widget).getText().trim(); validate(); } }); final Button browseButton = new Button(locContainer, SWT.PUSH); browseButton.setText("Browse..."); browseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String location = new DirectoryDialog(getShell()).open(); if (location != null) projectLocationText.setText(location); } }); useDefaultLocButton.setSelection(this.isAtDefaultLocation); useDefaultLocButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SharedLibraryNewWizardPage.this.isAtDefaultLocation = useDefaultLocButton.getSelection(); boolean use = !SharedLibraryNewWizardPage.this.isAtDefaultLocation; locLabel.setEnabled(use); projectLocationText.setEnabled(use); browseButton.setEnabled(use); projectLocationText.setFocus(); validate(); } }); slNameText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { SharedLibraryNewWizardPage.this.name = slNameText.getText().trim(); String slName = slNameText.getText().substring(10); String newGroupId = slGroupIdText.getText(); if (newGroupId.startsWith("org.ow2.petals.")) newGroupId = "org.ow2.petals." + slName; slGroupIdText.setText(newGroupId); // Validation is implicit, called by the group ID text } }); // Last steps in the UI definition useDefaultLocButton.notifyListeners(SWT.Selection, new Event()); setControl(container); }
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);// w w w . j a v a 2 s. c om 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.google.gdt.eclipse.suite.preferences.ui.ErrorsWarningsPage.java
License:Open Source License
private void addProblemTypeRow(Composite categoryProblemsPanel, IGdtProblemType problemType) { GridData problemLabelLayout = new GridData(SWT.FILL, SWT.CENTER, true, false); Label problemLabel = new Label(categoryProblemsPanel, SWT.NONE); problemLabel.setLayoutData(problemLabelLayout); problemLabel.setText(problemType.getDescription()); ComboViewer severityCombo = new ComboViewer(categoryProblemsPanel, SWT.READ_ONLY); GridData severityComboLayout = new GridData(SWT.FILL, SWT.CENTER, false, false); severityCombo.getCombo().setLayoutData(severityComboLayout); severityCombo.setContentProvider(new ArrayContentProvider()); severityCombo.setLabelProvider(severityLabelProvider); severityCombo.setSorter(severityViewerSorter); severityCombo.setInput(GdtProblemSeverity.values()); // Save the association between the problem type and this combo problemSeverityCombos.put(problemType, severityCombo); }