List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:org.jboss.tools.windup.ui.internal.editor.RulesetEditorRulesSection.java
License:Open Source License
private void createButtons(Composite parent) { Composite container = toolkit.createComposite(parent); toolkit.paintBordersFor(container);// w w w. j av a 2s. co m GridLayoutFactory.fillDefaults().applyTo(container); GridDataFactory.fillDefaults().grab(false, true).applyTo(container); Button addButton = createButton(container, Messages.RulesetEditor_AddRule); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Document document = (Document) treeViewer.getInput(); Element rulesetElement = domService.findOrCreateRulesetElement(document); Element rulesElement = domService.findOrCreateRulesElement(rulesetElement); //createRule(rulesElement); } }); this.removeButton = createButton(container, Messages.RulesetEditor_remove); removeButton.addSelectionListener(new SelectionAdapter() { @SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e) { removeNodes(((IStructuredSelection) treeViewer.getSelection()).toList()); } }); createPlaceholder(container); createPlaceholder(container); createPlaceholder(container); this.upButton = createButton(container, Messages.RulesetEditor_Rules_up); this.downButton = createButton(container, Messages.RulesetEditor_Rules_down); upButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) treeViewer.getSelection(); if (!ss.isEmpty() && ss.size() == 1) { Node node = (Node) ss.getFirstElement(); if (node instanceof Element && node.getParentNode() instanceof Element) { ISelection selection = treeViewer.getSelection(); domService.insertBeforePreviousSibling(node); treeViewer.setSelection(selection); } } } }); downButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) treeViewer.getSelection(); if (!ss.isEmpty() && ss.size() == 1) { Node node = (Node) ss.getFirstElement(); if (node instanceof Element && node.getParentNode() instanceof Element) { ISelection selection = treeViewer.getSelection(); domService.insertAfterNextSibling(node); treeViewer.setSelection(selection); } } } }); }
From source file:org.jboss.tools.windup.ui.internal.launch.OptionsRulesTab.java
License:Open Source License
private void createCustomRulesButtonBar(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container); GridDataFactory.fillDefaults().grab(false, true).applyTo(container); Button addButton = new Button(container, SWT.PUSH); addButton.setText(Messages.windupAdd); GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton); addButton.addSelectionListener(new SelectionAdapter() { @Override//from w w w . j ava2 s . c o m public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(parent.getShell()); String directory = dialog.open(); if (directory != null) { if (!configuration.getUserRulesDirectories().contains(directory)) { configuration.getUserRulesDirectories().add(directory); reloadCustomRules(); } } } }); Button removeButton = new Button(container, SWT.PUSH); removeButton.setText(Messages.windupRemove); GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) rulesDirectoryViewer.getSelection(); if (!ss.isEmpty()) { @SuppressWarnings("unchecked") List<String> paths = (List<String>) ss.toList(); configuration.getUserRulesDirectories().removeAll(paths); reloadCustomRules(); } } }); }
From source file:org.jboss.tools.windup.ui.internal.launch.OptionsRulesTab.java
License:Open Source License
private void createOptionsButtonBar(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container); GridDataFactory.fillDefaults().grab(false, true).applyTo(container); Button addButton = new Button(container, SWT.PUSH); addButton.setText(Messages.windupAdd); GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton); addButton.addSelectionListener(new SelectionAdapter() { @Override//from w ww . java2s . c o m public void widgetSelected(SelectionEvent e) { if (configurationOptions == null) { ProgressBar progress = new ProgressBar(parent.getShell(), SWT.HORIZONTAL | SWT.INDETERMINATE); progress.setLayoutData(new GridData(GridData.FILL_BOTH)); OptionsRulesTab.this.configurationOptions = WindupService.getWindupConfigurationOptions(); progress.dispose(); } OptionsDialog dialog = new OptionsDialog(parent.getShell(), configurationOptions); if (dialog.open() == IDialogConstants.OK_ID) { String option = dialog.getOption(); String value = dialog.getValue(); Pair pair = WindupFactory.eINSTANCE.createPair(); pair.setKey(option); pair.setValue(value); configuration.getOptions().add(pair); reloadOptions(); } } }); Button removeButton = new Button(container, SWT.PUSH); removeButton.setText(Messages.windupRemove); GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) optionsViewer.getSelection(); if (!ss.isEmpty()) { @SuppressWarnings("unchecked") List<Pair> options = (List<Pair>) ss.toList(); configuration.getOptions().removeAll(options); reloadOptions(); } } }); }
From source file:org.jboss.tools.windup.ui.internal.launch.OptionsTab.java
License:Open Source License
private void createOptionsButtonBar(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container); GridDataFactory.fillDefaults().grab(false, true).applyTo(container); Button addButton = new Button(container, SWT.PUSH); addButton.setText(Messages.windupAdd); GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton); addButton.addSelectionListener(new SelectionAdapter() { @Override/* w ww . j a va 2s . c o m*/ public void widgetSelected(SelectionEvent e) { OptionsDialog dialog = new OptionsDialog(parent.getShell(), modelService, optionsService, configuration); if (dialog.open() == IDialogConstants.OK_ID) { OptionDescription option = dialog.getSelectedOption(); String value = dialog.getSelectedOptionValue(); if (!value.isEmpty()) { Pair pair = WindupFactory.eINSTANCE.createPair(); pair.setKey(option.getName()); pair.setValue(value); configuration.getOptions().add(pair); if (IOptionKeys.outputOption.equals(option.getName())) { configuration.setOutputLocation(value); } } reloadOptions(); } } }); Button removeButton = new Button(container, SWT.PUSH); removeButton.setText(Messages.windupRemove); GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) optionsViewer.getSelection(); if (!ss.isEmpty()) { @SuppressWarnings("unchecked") List<Pair> options = (List<Pair>) ss.toList(); configuration.getOptions().removeAll(options); for (Pair option : options) { if (IOptionKeys.outputOption.equals(option.getKey())) { configuration.setOutputLocation(modelService.getDefaultOutputLocation(configuration)); } } reloadOptions(); } } }); }
From source file:org.jboss.tools.windup.ui.internal.launch.RulesTab.java
License:Open Source License
private void createCustomRulesButtonBar(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container); GridDataFactory.fillDefaults().grab(false, true).applyTo(container); Button addButton = new Button(container, SWT.PUSH); addButton.setText("Add..."); //$NON-NLS-1$ GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton); addButton.addSelectionListener(new SelectionAdapter() { @Override// www.j ava 2 s . c o m public void widgetSelected(SelectionEvent e) { FilteredListDialog dialog = new FilteredListDialog(parent.getShell(), new LabelProvider() { @Override public String getText(Object element) { CustomRuleProvider provider = (CustomRuleProvider) element; StringBuilder builder = new StringBuilder(); String parsedRulesetId = XMLRulesetModelUtil.getRulesetId(provider.getLocationURI()); if (parsedRulesetId != null && !parsedRulesetId.isEmpty()) { builder.append(parsedRulesetId); builder.append(" - "); //$NON-NLS-1$ } builder.append(provider.getLocationURI()); return builder.toString(); } @Override public Image getImage(Object element) { return WindupUIPlugin.getDefault().getImageRegistry().get(WindupUIPlugin.IMG_RULE_SET); } }); dialog.setMultipleSelection(true); dialog.setMessage(Messages.selectExistingRepositories); //modelService.cleanCustomRuleRepositories(configuration); List<CustomRuleProvider> providers = Lists .newArrayList(modelService.getModel().getCustomRuleRepositories()); providers = providers.stream() .filter(p -> !configuration.getUserRulesDirectories().contains(p.getLocationURI())) .collect(Collectors.toList()); dialog.setElements(providers.stream().toArray(CustomRuleProvider[]::new)); dialog.setTitle(Messages.selectRepositories); dialog.setHelpAvailable(false); dialog.create(); if (dialog.open() == Window.OK) { Object[] selected = (Object[]) dialog.getResult(); if (selected.length > 0) { List<String> rulesets = Lists.newArrayList(); // TODO: Temporary - see https://tree.taiga.io/project/rdruss-jboss-migration-windup-v3/task/884 selected = new Object[] { selected[0] }; //modelService.write(() -> configuration.getUserRulesDirectories().clear()); // Arrays.stream(selected) .forEach(p -> rulesets.add(((CustomRuleProvider) p).getLocationURI())); modelService.write(() -> { configuration.getUserRulesDirectories().addAll(rulesets); }); reload(); } } } }); removeButton = new Button(container, SWT.PUSH); removeButton.setText(Messages.windupRemove); GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StructuredSelection ss = (StructuredSelection) rulesRepositoryViewer.getSelection(); if (!ss.isEmpty()) { @SuppressWarnings("unchecked") List<CustomRuleProvider> providers = (List<CustomRuleProvider>) ss.toList(); List<String> paths = providers.stream().map(p -> p.getLocationURI()) .collect(Collectors.toList()); modelService.write(() -> { configuration.getUserRulesDirectories().removeAll(paths); }); reloadCustomRules(); } } }); rulesRepositoryViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { removeButton.setEnabled(!event.getSelection().isEmpty()); } }); removeButton.setEnabled(false); }
From source file:org.jlibrary.client.ui.versions.VersionBrowsingDialog.java
License:Open Source License
protected synchronized Control createDialogArea(Composite parent2) { Composite parent = (Composite) super.createDialogArea(parent2); getShell().setText(Messages.getMessage("restore_dialog_title")); getShell().setImage(SharedImages.getImage(SharedImages.IMAGE_RESTORE_VERSION)); Splitter vsplitter = new Splitter(parent, SWT.VERTICAL); vsplitter.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL)); fEditionPane = new CompareViewerPane(vsplitter, SWT.BORDER | SWT.FLAT); fEditionPane.setText(Messages.getMessage("restore_dialog_versions")); fEditionTree = new TreeViewer(fEditionPane, SWT.H_SCROLL + SWT.V_SCROLL); fEditionTree.setContentProvider(new CompareContentProvider()); fEditionTree.setLabelProvider(new CompareLabelProvider()); fEditionTree.setInput(createDocumentVersionNodes(document)); fEditionPane.setContent(fEditionTree.getTree()); Splitter hsplitter = new Splitter(vsplitter, SWT.HORIZONTAL); selectedVersionPane = new CompareViewerSwitchingPane(hsplitter, SWT.BORDER | SWT.FLAT) { protected Viewer getViewer(Viewer oldViewer, Object input) { return null; }// w ww . j a va 2 s .c om }; selectedVersionPane.setText(Messages.getMessage("version_selection")); editorVersionPane = new CompareViewerSwitchingPane(hsplitter, SWT.BORDER | SWT.FLAT) { protected Viewer getViewer(Viewer oldViewer, Object input) { return null; } }; editorVersionPane.setText(Messages.getMessage("version_current")); openDocument(editorVersionPane, document); vsplitter.setWeights(new int[] { 30, 70 }); applyDialogFont(parent); fEditionTree.addSelectionChangedListener(new ISelectionChangedListener() { /** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection.isEmpty()) { selectedVersionPane.setViewer(new NullViewer(selectedVersionPane)); fCommitButton.setEnabled(false); } DocumentVersionNode node = (DocumentVersionNode) selection.getFirstElement(); if (node.getChildren().size() > 0) { //It's a root selectedVersionPane.setViewer(new NullViewer(selectedVersionPane)); fCommitButton.setEnabled(false); return; } // It's a version openVersion(selectedVersionPane, node); fCommitButton.setEnabled(true); } }); return parent; }
From source file:org.locationtech.udig.feature.panel.TabLabelProvider.java
License:Open Source License
@Override public String getText(Object element) { if (element instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) element; if (sel.isEmpty()) { return "Please select a feature"; }/*from w ww. ja v a 2 s . c o m*/ element = sel.getFirstElement(); } if (element == null) { return null; } if (element instanceof SimpleFeature) { SimpleFeature feature = (SimpleFeature) element; if (delegate != null) { String text = delegate.getText(feature); if (text != null) { return text; } } return feature.getID(); } if (element instanceof FeaturePanelTabDescriptor) { FeaturePanelTabDescriptor tabDescriptor = (FeaturePanelTabDescriptor) element; String title = tabDescriptor.getEntry().getTitle(); if (title == null || title.length() == 0) { title = tabDescriptor.getLabel(); } return title; } else { String text = element.toString(); return text; } }
From source file:org.locationtech.udig.style.sld.editor.StyleThemePage.java
License:Open Source License
/** * @param compBottomLeftButtons/* www. j a va2 s .c o m*/ */ private void createRemoveButton(Composite compBottomLeftButtons) { Button removeButton = new Button(compBottomLeftButtons, SWT.RIGHT); removeButton.setText(Messages.StyleEditor_theme_remove); removeButton.setEnabled(false); removeButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { StructuredSelection selection = (StructuredSelection) treeViewer.getSelection(); if (selection.isEmpty()) return; Rule rule = (Rule) selection.getFirstElement(); if (removeRule(rule)) { treeViewer.refresh(); } else { //freak out } } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); pageControls.put(BUTTON_REMOVE, removeButton); }
From source file:org.nightlabs.jfire.simpletrade.admin.ui.producttype.create.CreateProductTypeAction.java
License:Open Source License
public CreateProductTypeAction(ProductTypeTree tree) { super(Messages.getString( "org.nightlabs.jfire.simpletrade.admin.ui.producttype.create.CreateProductTypeAction.text")); //$NON-NLS-1$ setEnabled(false);//w w w .j a v a 2 s . c o m this.tree = tree; tree.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { logger.debug("selection changed! selection: " + event.getSelection().getClass().getName() + ", " //$NON-NLS-1$//$NON-NLS-2$ + event.getSelection()); StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection.isEmpty()) selectedNode = null; else if (selection.getFirstElement() instanceof ProductTypeTreeNode) selectedNode = (ProductTypeTreeNode) selection.getFirstElement(); else selectedNode = null; setEnabled(selectedNode != null && selectedNode.getJdoObject().isInheritanceBranch()); } }); }
From source file:org.nightlabs.jfire.trade.admin.ui.gridpriceconfig.ProductTypeSelectorListImpl.java
License:Open Source License
@Override public void setSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; if (sel.isEmpty()) productTypeGUIList.setSelection(-1); else {/*from w w w .java2s. c o m*/ ProductType spi = (ProductType) sel.getFirstElement(); int idx = 0; for (Iterator it = productTypeItemList.iterator(); it.hasNext(); ++idx) { ProductType pi = (ProductType) it.next(); if (spi.getPrimaryKey().equals(pi.getPrimaryKey())) { productTypeGUIList.setSelection(idx); break; } } } } }