List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:net.sf.wickedshell.ui.batch.BatchManager.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *//*from w ww . j a v a2 s. c o m*/ public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (!selection.isEmpty()) { IBatchFileDescriptor descriptor = (IBatchFileDescriptor) selection.getFirstElement(); File selectedFile = new File(descriptor.getFilename()); try { char[] fileContentBuffer = new char[256]; StringBuffer fileContent = new StringBuffer(); FileReader fileReader = new FileReader(selectedFile); while (fileReader.read(fileContentBuffer) != -1) { fileContent.append(fileContentBuffer); } fileReader.close(); textBatchFile.setText(fileContent.toString()); } catch (IOException exception) { textBatchFile.setText("Error while reading selected file (" + exception.getMessage() + ")!"); } } else { textBatchFile.setText(""); } }
From source file:net.sourceforge.docfetcher.view.ViewerMenuManager.java
License:Open Source License
public ViewerMenuManager(Viewer viewer) { contextMenu = new MenuManager(); viewer.getControl().setMenu(contextMenu.createContextMenu(viewer.getControl())); // Update enabled state of actions according to current selection viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); setEnabled(nonEmptyActions, !selection.isEmpty()); setEnabled(singleElementActions, selection.size() == 1); if (rootChecker != null) { List<Object> rootSelection = new ArrayList<Object>(selection.size()); Iterator<?> it = selection.iterator(); while (it.hasNext()) { Object item = it.next(); if (rootChecker.isRoot(item)) // Only enable action for RootScopes (not for other Scopes) rootSelection.add(item); }//from w ww. j a v a2s .c om setEnabled(rootActions, rootSelection.size() > 0); } } private void setEnabled(List<Action> actions, boolean enabled) { for (Action action : actions) action.setEnabled(enabled); } }); // Activate context menu entries through keyboard shortcuts viewer.getControl().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { Key key = Key.getKey(e.stateMask, e.keyCode); if (key == null) return; Action action = keyActionMap.get(key); if (action != null && action.isEnabled()) action.run(); } }); }
From source file:net.sourceforge.eclipsefrills.resource.action.OpenAllResultsAction.java
License:Open Source License
/** * @see IViewActionDelegate#run(IAction) *///w w w . j a va2 s . c o m public void run(final IAction action) { final ISelection selection = viewPart.getSite().getSelectionProvider().getSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) selection; if (!sel.isEmpty()) { final List<Object> elements = new ArrayList<Object>(sel.size()); for (final Object obj : sel.toArray()) { if (!(obj instanceof IProject || obj instanceof IFolder)) { elements.add(obj); } } final StructuredSelection selAdapter = new StructuredSelection(elements); if (!selAdapter.isEmpty()) { final OpenFileAction openAction = new OpenFileAction( viewPart.getSite().getWorkbenchWindow().getActivePage()); openAction.selectionChanged(selAdapter); openAction.run(); } } } }
From source file:net.sourceforge.taggerplugin.action.OpenAllResultsAction.java
License:Open Source License
/** * @see IViewActionDelegate#run(IAction) */// ww w . j a va 2s . c om @SuppressWarnings("unchecked") public void run(IAction action) { final ISelection selection = viewPart.getSite().getSelectionProvider().getSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) selection; if (!sel.isEmpty()) { final List elements = new ArrayList(sel.size()); for (Object obj : sel.toArray()) { if (!(obj instanceof IProject || obj instanceof IFolder)) { elements.add(obj); } } final StructuredSelection selAdapter = new StructuredSelection(elements); if (!selAdapter.isEmpty()) { final OpenFileAction openAction = new OpenFileAction( viewPart.getSite().getWorkbenchWindow().getActivePage()); openAction.selectionChanged(selAdapter); openAction.run(); } } } }
From source file:nexcore.tool.uml.ui.project.explorer.action.CreateFragmentAllSubPackageAction.java
License:Open Source License
@Override public void run(IAction action) { final StructuredSelection ss = ((StructuredSelection) selection); if (ss.isEmpty()) { return;/*from ww w .j a v a 2 s. c o m*/ } start(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { dialog = new ProgressMonitorDialog(targetPart.getSite().getShell()); try { WorkspaceModifyOperation workspaceModifyOperation = new WorkspaceModifyOperation() { /** * @see org.eclipse.ui.actions.WorkspaceModifyOperation#execute(org.eclipse.core.runtime.IProgressMonitor) */ @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Create fragment", 150); saveResource = new HashSet<Resource>(); //////////////// ResourceSetImpl resourceSet = (ResourceSetImpl) DomainRegistry.getUMLDomain() .getResourceSet(); Map<URI, Resource> uriResourceMap = resourceSet.getURIResourceMap(); Set<Resource> modifiedResource = new HashSet<Resource>(); for (Iterator<?> iterator = uriResourceMap.values().iterator(); iterator.hasNext();) { Resource resource = (Resource) iterator.next(); if (ProjectUtil.isModelFile(resource)) { if (resource.isModified()) { modifiedResource.add(resource); } } } SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 20); subMonitor.beginTask("Save", modifiedResource.size()); for (Resource r : modifiedResource) { subMonitor.worked(1); try { subMonitor.subTask(r.getURI().toString()); System.out.println("------------------------>" + r.getURI().toString()); DomainModelHandlerUtil.save(r, false); } catch (Exception e) { ALMLogger.getLog(ProjectExplorerPlugin.PLUGIN_ID).error(e.getMessage(), e); } } subMonitor.done(); /////////////// closeEditor(); /////////////// TreeMap<String, Package> packageList = new TreeMap<String, Package>(); for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { Object obj = (Object) iterator.next(); if (obj instanceof ITreeNode) { ITreeNode node = (ITreeNode) obj; EObject eObject = node.getEObject(); Package selectedPackage = null; if (eObject instanceof Model) { selectedPackage = (Model) eObject; } else if (eObject instanceof Package) { selectedPackage = (Package) eObject; } if (packageList.containsKey(selectedPackage.getQualifiedName())) { continue; } SELECT statement = new SELECT(new FROM(selectedPackage), new WHERE( new EObjectTypeRelationCondition(UMLPackage.eINSTANCE.getPackage()))); IQueryResult result = statement.execute(); for (Iterator<?> ir = result.iterator(); ir.hasNext();) { Package pkg = (Package) ir.next(); if (pkg == null || pkg.getQualifiedName() == null) { continue; } if (AdapterFactoryEditingDomain.isControlled(pkg)) { continue; } packageList.put(pkg.getQualifiedName(), pkg); } // model ? Model ? Package ? // model ? ?? ? if (!(selectedPackage instanceof Model)) { packageList.put(selectedPackage.getQualifiedName(), selectedPackage); } } } subMonitor = new SubProgressMonitor(monitor, 100); subMonitor.beginTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING, packageList.size()); for (Iterator<String> ir = packageList.descendingKeySet().iterator(); ir.hasNext();) { subMonitor.worked(1); String qualifiedName = (String) ir.next(); subMonitor.subTask(qualifiedName); createFragment(packageList.get(qualifiedName), subMonitor); } subMonitor.done(); subMonitor = new SubProgressMonitor(monitor, 10); subMonitor.beginTask("Resolve all resource", saveResource.size()); for (Iterator<Resource> ir = saveResource.iterator(); ir.hasNext();) { subMonitor.worked(1); Resource resource = ir.next(); subMonitor.subTask(String.format("save : %s", resource.getURI())); EcoreUtil.resolveAll(resource); } subMonitor.done(); subMonitor = new SubProgressMonitor(monitor, 20); subMonitor.beginTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING, saveResource.size()); subMonitor.setTaskName(UMLMessage.TITLE_SAVE); for (Resource resource : saveResource) { subMonitor.worked(1); subMonitor.subTask(String.format("%s", resource.getURI())); try { DomainModelHandlerUtil.save(resource, true); } catch (Exception e) { e.printStackTrace(); } finally { System.out.println(String.format("saved : %s", resource.getURI())); } } subMonitor.done(); monitor.done(); } }; dialog.run(true, false, workspaceModifyOperation); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { saveResource.clear(); done(); } } }); }
From source file:nexcore.tool.uml.ui.project.explorer.action.MergeAllSubPackageAction.java
License:Open Source License
@Override public void run(IAction action) { final StructuredSelection ss = ((StructuredSelection) selection); if (ss.isEmpty()) { return;// w w w .j a va 2 s . c om } if (!MessageDialog.openConfirm(UiCorePlugin.getShell(), UMLMessage.getMessage(UMLMessage.LABEL_FILE_DEFRAGMENTATION), UMLMessage.getMessage(UMLMessage.MESSAGE_CONFIRM_MERGE))) { return; } parentObjectList = new ArrayList<EObject>(); removeResourceList = new ArrayList<Resource>(); deleteFileList = new ArrayList<Resource>(); saveResource = new HashSet<Resource>(); CommonViewer commonViewer = ViewerRegistry.getViewer(); expanedTreePaths = TreeItemUtil.getExpandTreePaths(commonViewer.getTree()).clone(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { dialog = new ProgressMonitorDialog(targetPart.getSite().getShell()); try { WorkspaceModifyOperation workspaceModifyOperation = new WorkspaceModifyOperation() { /** * @see org.eclipse.ui.actions.WorkspaceModifyOperation#execute(org.eclipse.core.runtime.IProgressMonitor) */ @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Merge fragment", 140); TreeMap<String, Package> packageList = new TreeMap<String, Package>(); for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { Object obj = (Object) iterator.next(); if (obj instanceof ITreeNode) { ITreeNode node = (ITreeNode) obj; EObject eObject = node.getEObject(); Package selectedPackage = null; if (eObject instanceof Model) { selectedPackage = (Model) eObject; } else if (eObject instanceof Package) { selectedPackage = (Package) eObject; } if (packageList.containsKey(selectedPackage.getQualifiedName())) { continue; } SELECT statement = new SELECT(new FROM(selectedPackage), new WHERE( new EObjectTypeRelationCondition(UMLPackage.eINSTANCE.getPackage()))); IQueryResult result = statement.execute(); for (Iterator<?> ir = result.iterator(); ir.hasNext();) { Package pkg = (Package) ir.next(); if (pkg == null || pkg.getQualifiedName() == null) { continue; } if (AdapterFactoryEditingDomain.isControlled(pkg)) { packageList.put(pkg.getQualifiedName(), pkg); } } // model ? Model ? Package ? // model ? ?? ? if (!(selectedPackage instanceof Model)) { packageList.put(selectedPackage.getQualifiedName(), selectedPackage); } } } SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 100); subMonitor.beginTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING, packageList.size()); for (Iterator<String> ir = packageList.descendingKeySet().iterator(); ir.hasNext();) { subMonitor.worked(1); String qualifiedName = (String) ir.next(); subMonitor.subTask(qualifiedName); Package eobject = packageList.get(qualifiedName); if (!(AdapterFactoryEditingDomain.isControlled(eobject))) { subMonitor.worked(1); continue; } mergeFragment(eobject, subMonitor); } subMonitor.done(); subMonitor = new SubProgressMonitor(monitor, 20); subMonitor.beginTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING, saveResource.size()); subMonitor.setTaskName(UMLMessage.TITLE_SAVE); for (Resource resource : saveResource) { subMonitor.worked(1); subMonitor.subTask(String.format("%s", resource.getURI())); try { IFile file = WorkspaceSynchronizer.getFile(resource); if (file == null || !file.exists()) { continue; } DomainModelHandlerUtil.save(resource, true); } catch (Exception e) { e.printStackTrace(); } finally { System.out.println(String.format("saved : %s", resource.getURI())); } } for (URI uri : removeTreeNode) { UMLTreeNodeRegistry.removeTreeNode(uri); } for (Resource sourceResource : removeResourceList) { ResourceUnloader.getInstance().put(sourceResource); } subMonitor = new SubProgressMonitor(monitor, 10); subMonitor.beginTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING, deleteFileList.size()); subMonitor.setTaskName(UMLMessage.TITLE_DELETE_FILE/* " ? " */); try { for (Resource resource : deleteFileList) { IFile file = WorkspaceSynchronizer.getFile(resource); if (file == null) { continue; } subMonitor.subTask(String.format("%s", file.getFullPath().toString())); URI uri = URI.createURI(file.getFullPath().toString()); Map<URI, Resource> uriResourceMap = ((ResourceSetImpl) DomainRegistry .getUMLDomain().getResourceSet()).getURIResourceMap(); if (uriResourceMap.containsKey(uri)) { uriResourceMap.remove(uri); } // file.delete(false, new NullProgressMonitor()); resource.delete(Collections.emptyMap()); } } catch (Exception ex) { ex.printStackTrace(); } subMonitor = new SubProgressMonitor(monitor, 10); subMonitor.beginTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING, parentObjectList.size()); subMonitor.setTaskName(UMLMessage.TITLE_REFRESH); subMonitor.subTask(UICoreConstant.PROJECT_CONSTANTS__EMPTY_STRING); for (EObject parentObject : parentObjectList) { subMonitor.worked(1); try { ProjectUtil.refreshNodeInExplorer(parentObject); } catch (Exception e) { // ignore } } subMonitor.done(); monitor.done(); } }; dialog.run(true, false, workspaceModifyOperation); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); }
From source file:org.apache.directory.studio.apacheds.configuration.editor.LdapLdapsServersPage.java
License:Apache License
/** * Gets the selected hashing method.//ww w . j ava 2 s . c o m * * @return the selected hashing method */ private LdapSecurityConstants getSelectedHashingMethod() { StructuredSelection selection = (StructuredSelection) hashingMethodComboViewer.getSelection(); if (!selection.isEmpty()) { return (LdapSecurityConstants) selection.getFirstElement(); } return null; }
From source file:org.apache.directory.studio.apacheds.configuration.editor.LdapLdapsServersPage.java
License:Apache License
/** * Gets the first SASL realms Table //from ww w.j a v a 2 s.co m * * @return the first Enabled Protocols Table */ private String getSelectedSaslRealms() { StructuredSelection selection = (StructuredSelection) saslRealmsTableViewer.getSelection(); if (!selection.isEmpty()) { return (String) selection.getFirstElement(); } return null; }
From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionDetailsPage.java
License:Apache License
/** * Opens an indexed dialog with the selected index in the indexes table viewer. *///from w ww .j av a 2s . com private void editSelectedIndex() { StructuredSelection selection = (StructuredSelection) indexesTableViewer.getSelection(); if (!selection.isEmpty()) { PartitionType partitionType = (PartitionType) ((StructuredSelection) partitionTypeComboViewer .getSelection()).getFirstElement(); if (partitionType != null) { IndexBean editedIndex = null; // JDBM partition if (partitionType == PartitionType.JDBM) { // Getting the selected JDBM index JdbmIndexBean index = (JdbmIndexBean) selection.getFirstElement(); // Creating a JDBM dialog JdbmIndexDialog dialog = new JdbmIndexDialog(index); if (JdbmIndexDialog.OK == dialog.open() && dialog.isDirty()) { editedIndex = index; } } // Mavibot Partition else if (partitionType == PartitionType.MAVIBOT) { // Getting the selected Mavibot index MavibotIndexBean index = (MavibotIndexBean) selection.getFirstElement(); // Creating a Mavibot dialog MavibotIndexDialog dialog = new MavibotIndexDialog(index); if (MavibotIndexDialog.OK == dialog.open() && dialog.isDirty()) { editedIndex = index; } } // Checking the new index if (editedIndex != null) { indexesTableViewer.refresh(); masterDetailsBlock.setEditorDirty(); } } } }
From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionDetailsPage.java
License:Apache License
/** * Opens a Context Entry Dialog with the selected Attribute Value Object in the * Context Entry Table Viewer.//from w ww . ja v a2 s .c o m */ private void editSelectedContextEntry() { StructuredSelection selection = (StructuredSelection) contextEntryTableViewer.getSelection(); if (!selection.isEmpty()) { AttributeValueObject attributeValueObject = (AttributeValueObject) selection.getFirstElement(); String oldId = attributeValueObject.getAttribute(); String oldValue = attributeValueObject.getValue(); AttributeValueDialog dialog = new AttributeValueDialog(attributeValueObject); if (AttributeValueDialog.OK == dialog.open() && dialog.isDirty()) { Attribute attribute = contextEntry.get(oldId); if (attribute != null) { attribute.remove(oldValue); } AttributeValueObject newAttributeValueObject = dialog.getAttributeValueObject(); attribute = contextEntry.get(newAttributeValueObject.getAttribute()); if (attribute != null) { try { attribute.add(newAttributeValueObject.getValue()); } catch (LdapInvalidAttributeValueException liave) { // Will never occur } } else { try { contextEntry.put(new DefaultAttribute(newAttributeValueObject.getAttribute(), newAttributeValueObject.getValue())); } catch (LdapException e) { // Will never occur } } contextEntryTableViewer.refresh(); resizeContextEntryTableColumnsToFit(); masterDetailsBlock.setEditorDirty(); // dirty = true; TODO commit(true); } } }