List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:org.apache.directory.studio.schemaeditor.controller.actions.RenameProjectAction.java
License:Apache License
/** * {@inheritDoc}/*from ww w . j av a2s .c o m*/ */ public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { Project project = ((ProjectWrapper) selection.getFirstElement()).getProject(); RenameProjectDialog dialog = new RenameProjectDialog(project.getName()); if (dialog.open() == Dialog.OK) { projectsHandler.renameProject(project, dialog.getNewName()); } } }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.RenameSchemaElementAction.java
License:Apache License
/** * Creates a new instance of RenameProjectAction. * * @param viewer//from www. java 2s . c o m * the associated viewer */ public RenameSchemaElementAction(TreeViewer viewer) { super(Messages.getString("RenameSchemaElementAction.RenameSchemaElementAction")); //$NON-NLS-1$ setToolTipText(getText()); setId(PluginConstants.CMD_RENAME_SCHEMA_ELEMENT); setActionDefinitionId(PluginConstants.CMD_RENAME_SCHEMA_ELEMENT); setImageDescriptor(Activator.getDefault().getImageDescriptor(PluginConstants.IMG_RENAME)); setEnabled(false); this.viewer = viewer; this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); setEnabled((selection.size() == 1) && ((selection.getFirstElement() instanceof SchemaWrapper) || (selection.getFirstElement() instanceof AttributeTypeWrapper) || (selection.getFirstElement() instanceof ObjectClassWrapper))); } }); }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.RenameSchemaElementAction.java
License:Apache License
/** * {@inheritDoc}/* ww w . j a v a 2s .c o m*/ */ public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { Object selectedElement = selection.getFirstElement(); // Saving all dirty editors before processing the renaming if (EditorsUtils.saveAllDirtyEditors()) { // SCHEMA if (selectedElement instanceof SchemaWrapper) { Schema schema = ((SchemaWrapper) selectedElement).getSchema(); RenameSchemaDialog dialog = new RenameSchemaDialog(schema.getSchemaName()); if (dialog.open() == RenameSchemaDialog.OK) { Activator.getDefault().getSchemaHandler().renameSchema(schema, dialog.getNewName()); } } // ATTRIBUTE TYPE else if (selectedElement instanceof AttributeTypeWrapper) { MutableAttributeType attributeType = (MutableAttributeType) ((AttributeTypeWrapper) selectedElement) .getAttributeType(); RenameAttributeTypeDialog dialog = new RenameAttributeTypeDialog(attributeType.getNames()); if (dialog.open() == RenameAttributeTypeDialog.OK) { MutableAttributeType modifiedAttributeType = PluginUtils.getClone(attributeType); modifiedAttributeType.setNames(dialog.getAliases()); Activator.getDefault().getSchemaHandler().modifyAttributeType(attributeType, modifiedAttributeType); } } // OBJECT CLASS else if (selectedElement instanceof ObjectClassWrapper) { MutableObjectClass objectClass = (MutableObjectClass) ((ObjectClassWrapper) selectedElement) .getObjectClass(); RenameObjectClassDialog dialog = new RenameObjectClassDialog(objectClass.getNames()); if (dialog.open() == RenameObjectClassDialog.OK) { ObjectClass modifiedObjectClass = PluginUtils.getClone(objectClass); modifiedObjectClass.setNames(dialog.getAliases()); Activator.getDefault().getSchemaHandler().modifyObjectClass(objectClass, modifiedObjectClass); } } } } }
From source file:org.apache.directory.studio.schemaeditor.controller.ProjectsViewController.java
License:Apache License
/** * Initializes the DoubleClickListener.// w ww.j a va2 s.c o m */ private void initDoubleClickListener() { viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { Project project = ((ProjectWrapper) selection.getFirstElement()).getProject(); if (project.getState().equals(ProjectState.CLOSED)) { projectsHandler.openProject(project); } } } }); }
From source file:org.apache.directory.studio.templateeditor.view.preferences.TemplateEntryEditorPreferencePage.java
License:Apache License
/** * Updates the states of the buttons./*from w ww. j a v a 2 s. c om*/ */ @SuppressWarnings("unchecked") private void updateButtonsStates() { StructuredSelection selection = (StructuredSelection) templatesViewer.getSelection(); if (!selection.isEmpty()) { if (selection.size() == 1) { // Only one row is selected Object selectedObject = selection.getFirstElement(); removeTemplateButton.setEnabled((selectedObject instanceof FileTemplate) || (selectedObject instanceof PreferencesFileTemplate)); // If we're in the object class presentation, we need to update the 'Set Default' button if (store.getInt( EntryTemplatePluginConstants.PREF_TEMPLATES_PRESENTATION) == EntryTemplatePluginConstants.PREF_TEMPLATES_PRESENTATION_OBJECT_CLASS) { if (selectedObject instanceof Template) { Template selectedTemplate = (Template) selectedObject; setDefaultTemplateButton.setEnabled((manager.isEnabled(selectedTemplate) && (!manager.isDefaultTemplate(selectedTemplate)))); } else { setDefaultTemplateButton.setEnabled(false); } } } else { // More than one row is selected removeTemplateButton.setEnabled(true); Iterator<Object> selectionIterator = ((StructuredSelection) templatesViewer.getSelection()) .iterator(); while (selectionIterator.hasNext()) { Object selectedObject = selectionIterator.next(); if (!((selectedObject instanceof FileTemplate) || (selectedObject instanceof PreferencesFileTemplate))) { removeTemplateButton.setEnabled(false); break; } } // If we're in the object class presentation, we need to update the 'Set Default' button if (store.getInt( EntryTemplatePluginConstants.PREF_TEMPLATES_PRESENTATION) == EntryTemplatePluginConstants.PREF_TEMPLATES_PRESENTATION_OBJECT_CLASS) { setDefaultTemplateButton.setEnabled(false); } } } else { removeTemplateButton.setEnabled(false); setDefaultTemplateButton.setEnabled(false); } }
From source file:org.bonitasoft.studio.document.ui.DocumentPropertySection.java
License:Open Source License
@Override public void selectionChanged(final SelectionChangedEvent event) { final StructuredSelection listSelection = (StructuredSelection) event.getSelection(); removeButton.setEnabled(!listSelection.isEmpty()); editButton.setEnabled(listSelection.size() == 1); }
From source file:org.brainwy.liclipsetext.editor.outline.LiClipseParsedModel.java
License:Open Source License
public ISimpleNode[] getSelectionPosition(StructuredSelection sel) { if (sel.size() == 1) { // only sync the editing view if it is a single-selection Object firstElement = sel.getFirstElement(); LiClipseNode node = ((LiClipseParsedItem) firstElement).getNode(); return new ISimpleNode[] { node }; }//from w w w . ja va2 s .c o m return null; }
From source file:org.brainwy.liclipsetext.shared_ui.outline.BaseOutlinePage.java
License:Open Source License
/** * create the outline view widgets// w ww . jav a 2s .co m */ @Override public void createControl(Composite parent) { super.createControl(parent); // this creates a tree viewer try { createParsedOutline(); // selecting an item in the outline scrolls the document selectionListener = new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { if (linkWithEditor == null) { return; } try { unlinkAll(); StructuredSelection sel = (StructuredSelection) event.getSelection(); boolean alreadySelected = false; if (sel.size() == 1) { // only sync the editing view if it is a single-selection IParsedItem firstElement = (IParsedItem) sel.getFirstElement(); ErrorDescription errorDesc = firstElement.getErrorDesc(); //select the error if (errorDesc != null && errorDesc.message != null) { int len = errorDesc.errorEnd - errorDesc.errorStart; editorView.setSelection(errorDesc.errorStart, len); alreadySelected = true; } } if (!alreadySelected) { ISimpleNode[] node = getOutlineModel().getSelectionPosition(sel); editorView.revealModelNodes(node); } } finally { relinkAll(); } } }; addSelectionChangedListener(selectionListener); createActions(); //OK, instead of using the default selection engine, we recreate it only to handle mouse //and key events directly, because it seems that sometimes, SWT creates spurious select events //when those shouldn't be created, and there's also a risk of creating loops with the selection, //as when one selection arrives when we're linked, we have to perform a selection and doing that //selection could in turn trigger a new selection, so, we remove that treatment and only start //selections from interactions the user did. //see: Cursor jumps to method definition when an error is detected //https://sourceforge.net/tracker2/?func=detail&aid=2057092&group_id=85796&atid=577329 TreeViewer treeViewer = getTreeViewer(); treeViewer.removeSelectionChangedListener(this); Tree tree = treeViewer.getTree(); tree.addMouseListener(new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) { tryToMakeSelection(); } @Override public void mouseDown(MouseEvent e) { } @Override public void mouseUp(MouseEvent e) { tryToMakeSelection(); } }); tree.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { tryToMakeSelection(); } } }); onControlCreated.call(getTreeViewer()); createdCallbacksForControls = callRecursively(onControlCreated, filter, new ArrayList()); } catch (Throwable e) { Log.log(e); } }
From source file:org.dawb.common.ui.wizard.ResourceChoosePage.java
License:Open Source License
protected List<String> getSelectedFiles() { if (selectedFiles != null) return selectedFiles; try {/*from w ww . j a va 2 s . c om*/ ISelection selection = EclipseUtils.getActivePage().getSelection(); StructuredSelection s = (StructuredSelection) selection; if (s.isEmpty()) return null; if (s.toArray() == null) return null; final Object[] oa = s.size() > 1 ? s.toArray() : getObjects(s.getFirstElement()); final List<String> ret = new ArrayList<String>(oa.length); for (final Object object : oa) { final File file = FileUtils.getFile(object); if (!file.isFile()) continue; ret.add(file.getAbsolutePath()); } return ret.size() > 0 ? ret : null; } catch (Throwable ignored) { return null; } }
From source file:org.dawnsci.fileviewer.table.FileTableExplorer.java
License:Open Source License
/** * Returns the selected files in the table * @return/*from w w w .ja v a2 s. c om*/ */ public File[] getSelectedFiles() { StructuredSelection selection = (StructuredSelection) tviewer.getSelection(); return Arrays.copyOf(selection.toArray(), selection.size(), File[].class); }