List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.mentor.nucleus.bp.core.util.TransactionUtil.java
License:Open Source License
/** * Checks the current selection to see if any read only ones will * be affected. A dialog is displayed which gives the user the * chance to cancel the transaction in case of read only resource * existence.// w w w .j a v a 2 s .co m */ public static boolean modifySelectedResources(String title, String message) { boolean readonlyItemFound = false; IStructuredSelection selection = Selection.getInstance().getStructuredSelection(); for (int i = 0; i < selection.size(); i++) { if (selection.toList().get(i) instanceof NonRootModelElement) { NonRootModelElement nrme = (NonRootModelElement) selection.toList().get(i); if (PersistenceManager.getHierarchyMetaData().isComponentRoot(nrme)) { if ((nrme != null) && (nrme.getFile() != null)) { ResourceAttributes attributes = nrme.getFile().getResourceAttributes(); if (attributes != null && attributes.isReadOnly()) { readonlyItemFound = true; break; } } } } } if (readonlyItemFound) { Shell context = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); boolean result = UIUtil.openQuestion(context, title, message, true); if (result == true) { // We need to change the readonly status of the file if we are // dealing with a rename as operating systems leave the renamed // file as readonly. This causes a problem for us as later we must // persist the name change. // // If there is only one item in the selection, change the file status // to writable. If only one item exists we are dealing with either // the deletion of one element (in which case it does not matter if // we change the file status) or a rename in which case we must change // the status if (selection.size() == 1) { NonRootModelElement nrme = (NonRootModelElement) selection.toList().get(0); if (PersistenceManager.getHierarchyMetaData().isComponentRoot(nrme)) { if ((nrme != null) && (nrme.getFile() != null)) { ResourceAttributes attributes = nrme.getFile().getResourceAttributes(); if (attributes != null) { attributes.setReadOnly(false); try { nrme.getFile().setResourceAttributes(attributes); } catch (CoreException e) { CorePlugin.logError("Unable to set component as writable.", e); } } } } } } return result; } else { return true; } }
From source file:com.mentor.nucleus.bp.debug.ui.actions.BPBreakpointPropertiesAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (ss.isEmpty() || ss.size() > 1) { return; }/*from ww w . ja v a 2 s . c o m*/ Object element = ss.getFirstElement(); if (element instanceof BPBreakpoint) { setBreakpoint((BPBreakpoint) element); } } }
From source file:com.mentor.nucleus.bp.debug.ui.actions.CreateBPBreakpointAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (ss.isEmpty() || ss.size() > 1) { return; }/*w w w.ja v a2 s . c o m*/ Object element = ss.getFirstElement(); if (element instanceof NonRootModelElement) { setElement((NonRootModelElement) element); } if (determineBreakpoint() == null) { action.setText("Set Breakpoint"); } else { action.setText("Remove Breakpoint"); } } }
From source file:com.mentor.nucleus.bp.debug.ui.launch.LaunchVerifierAction.java
License:Open Source License
public void run(IAction action) { IStructuredSelection selection = (IStructuredSelection) Selection.getInstance().getStructuredSelection(); if ((selection == null) || selection.isEmpty()) { return;/*from w w w . ja v a2 s .c om*/ } if (selection.size() == 1) { Object context = selection.getFirstElement(); if (context instanceof SystemModel_c) { IProject prj = (IProject) ((SystemModel_c) context).getAdapter(IProject.class); launchProject(prj); } else { if (context instanceof Domain_c || context instanceof ComponentReference_c) { launchMultipleModel(new NonRootModelElement[] { (NonRootModelElement) context }); } if (context instanceof Component_c) { Component_c component = (Component_c) context; List<NonRootModelElement> list = new ArrayList<NonRootModelElement>(); list.add(component); NonRootModelElement[] children = BPDebugUtils.getComponentChildren(component); for (int i = 0; i < children.length; i++) { list.add(children[i]); } launchMultipleModel(list.toArray(new NonRootModelElement[list.size()])); } if (context instanceof ComponentPackage_c) { NonRootModelElement[] componentPackageChildren = BPDebugUtils .getComponentPackageChildren((ComponentPackage_c) context); launchMultipleModel(componentPackageChildren); } if (context instanceof Package_c) { NonRootModelElement[] packageChildren = BPDebugUtils.getPackageChildren((Package_c) context); launchMultipleModel(packageChildren); } } } else { Vector<NonRootModelElement> model = null; Iterator ite = selection.iterator(); while (ite.hasNext()) { Object o = ite.next(); if (o instanceof Domain_c) { if (model == null) { model = new Vector<NonRootModelElement>(); } model.add((NonRootModelElement) o); } else if (o instanceof Component_c) { if (model == null) { model = new Vector<NonRootModelElement>(); } model.add((NonRootModelElement) o); NonRootModelElement[] children = BPDebugUtils.getComponentChildren((Component_c) o); for (int i = 0; i < children.length; i++) { model.add(children[i]); } } else if (o instanceof ComponentReference_c) { if (model == null) { model = new Vector<NonRootModelElement>(); } Component_c component = Component_c.getOneC_COnR4201((ComponentReference_c) o); model.add(component); NonRootModelElement[] children = BPDebugUtils.getComponentChildren(component); for (int i = 0; i < children.length; i++) { model.add(children[i]); } } else if (o instanceof ComponentPackage_c) { if (model == null) { model = new Vector<NonRootModelElement>(); } ComponentPackage_c compPackage = (ComponentPackage_c) o; NonRootModelElement[] children = BPDebugUtils.getComponentPackageChildren(compPackage); for (int i = 0; i < children.length; i++) { model.add(children[i]); } } else if (o instanceof Package_c) { if (model == null) { model = new Vector<NonRootModelElement>(); } Package_c pkg = (Package_c) o; NonRootModelElement[] children = BPDebugUtils.getPackageChildren(pkg); for (int i = 0; i < children.length; i++) { model.add(children[i]); } } } if (model != null) { launchMultipleModel(model.toArray(new NonRootModelElement[model.size()])); } } }
From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.SynchronizedTreeViewer.java
License:Open Source License
protected boolean includeMoveUpOperation() { if ((getMergeViewer().getLeftViewer() == this && !getMergeViewer().isLeftEditable()) || (getMergeViewer().getRightViewer() == this && !getMergeViewer().isRightEditable())) { return false; }//from w w w. ja v a 2 s . c o m IStructuredSelection selection = (IStructuredSelection) getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); Object realElement = ((ComparableTreeObject) element).getRealElement(); if (MetadataSortingManager.isOrderedElement(realElement)) { try { Method method = realElement.getClass().getMethod("Actionfilter", //$NON-NLS-1$ new Class[] { String.class, String.class }); Boolean bool = (Boolean) method.invoke(realElement, new Object[] { "can", "move up" }); //$NON-NLS-1$ $NON-NLS-2$ return bool; } catch (SecurityException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (NoSuchMethodException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (IllegalArgumentException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (IllegalAccessException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (InvocationTargetException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } } } return false; }
From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.SynchronizedTreeViewer.java
License:Open Source License
protected boolean includeMoveDownOperation() { if ((getMergeViewer().getLeftViewer() == this && !getMergeViewer().isLeftEditable()) || (getMergeViewer().getRightViewer() == this && !getMergeViewer().isRightEditable())) { return false; }//from w ww .ja v a2 s .c o m IStructuredSelection selection = (IStructuredSelection) getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); Object realElement = ((ComparableTreeObject) element).getRealElement(); if (MetadataSortingManager.isOrderedElement(realElement)) { try { Method method = realElement.getClass().getMethod("Actionfilter", //$NON-NLS-1$ new Class[] { String.class, String.class }); Boolean bool = (Boolean) method.invoke(realElement, new Object[] { "can", "move down" }); //$NON-NLS-1$ $NON-NLS-2$ return bool; } catch (SecurityException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (NoSuchMethodException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (IllegalArgumentException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (IllegalAccessException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } catch (InvocationTargetException e) { CorePlugin.logError("Unable to test for ordering ability.", e); } } } return false; }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.CanvasCopyAction.java
License:Open Source License
public static Object getImageDataForSelection(GraphicalEditor editor) { ///*ww w. j a v a2 s .c om*/ // Compute the required height and width to render boolean considerAll = false; IStructuredSelection selection = (IStructuredSelection) editor.getSite().getSelectionProvider() .getSelection(); if (!selection.isEmpty()) { if (selection.size() == 1 && selection.getFirstElement() instanceof DiagramEditPart) { // treat this as no selection considerAll = true; } } List<GraphicalEditPart> symbols = new ArrayList<GraphicalEditPart>(); if (considerAll) { symbols = GraphicalEditor.getAllSymbols((GraphicalViewer) editor.getAdapter(GraphicalViewer.class), editor.getModel().Hascontainersymbol()); } else { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object next = iterator.next(); if (next instanceof GraphicalEditPart) { if (next instanceof DiagramEditPart) continue; else symbols.add((GraphicalEditPart) next); } } } Rectangle extentRectangle = GraphicalZoomManager.getExtentRectangle(symbols); // // Set up the canvas for drawing. Rectangle client = new Rectangle(extentRectangle.x, extentRectangle.y, extentRectangle.width, extentRectangle.height); Image canvasImage = new Image(editor.getCanvas().getDisplay(), new org.eclipse.swt.graphics.Rectangle(client.x, client.y, client.width, client.height)); GraphicalViewer viewer = (GraphicalViewer) editor.getAdapter(GraphicalViewer.class); PrintDiagramOperation.printImage(canvasImage, viewer, extentRectangle, editor.getModel().Hascontainersymbol(), PrintDiagramOperation.NO_FIT); return canvasImage.getImageData(); }
From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerConfigPage.java
License:Open Source License
private void updateDockerSubscriptionComboBox(Composite mainContainer) { dockerSubscriptionComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override/* w ww . j a v a 2 s. c om*/ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() > 0) { AzureDockerSubscription currentSubscription = (AzureDockerSubscription) selection .getFirstElement(); dockerSubscriptionIdTextField .setText(currentSubscription != null ? currentSubscription.id : ""); errDispatcher.removeMessage("dockerSubscriptionCombo", dockerSubscriptionCombo); updateDockerLocationComboBox(mainContainer, currentSubscription); updateDockerHostSelectRGComboBox(mainContainer, currentSubscription); String region = (String) dockerLocationComboBox.getText(); Region regionObj = Region.findByLabelOrName(region); updateDockerSelectVnetComboBox(mainContainer, currentSubscription, regionObj != null ? regionObj.name() : region); updateDockerSelectStorageComboBox(mainContainer, currentSubscription); setPageComplete(doValidate()); } else { errDispatcher.addMessage("dockerSubscriptionCombo", "No active subscriptions found", null, IMessageProvider.ERROR, dockerSubscriptionCombo); setPageComplete(false); } } }); dockerSubscriptionComboViewer.setContentProvider(ArrayContentProvider.getInstance()); dockerSubscriptionComboViewer.setInput(dockerManager.getSubscriptionsList()); if (dockerManager.getSubscriptionsList() != null && dockerManager.getSubscriptionsList().size() > 0) { dockerSubscriptionCombo.select(0); dockerSubscriptionIdTextField.setText( ((AzureDockerSubscription) ((StructuredSelection) dockerSubscriptionComboViewer.getSelection()) .getFirstElement()).id); } }
From source file:com.microsoft.tfs.client.common.ui.controls.vc.checkin.actions.CompareChangeWithLatestVersionAction.java
License:Open Source License
@Override protected boolean computeEnablement(final IStructuredSelection selection) { if (selection.size() != 1) { return false; }/*w ww . jav a 2 s . c om*/ final Change change = (Change) adaptSelectionFirstElement(Change.class); if (change.getItem().getItemType() != ItemType.FILE || containsSymlinkChange(change)) { return false; } return !change.getChangeType().contains(ChangeType.DELETE); }
From source file:com.microsoft.tfs.client.common.ui.controls.vc.checkin.actions.CompareChangeWithPreviousVersionAction.java
License:Open Source License
@Override protected boolean computeEnablement(final IStructuredSelection selection) { if (selection.size() != 1) { return false; }// w w w.ja va 2 s.co m final Change change = (Change) adaptSelectionFirstElement(Change.class); if (change.getItem().getItemType() != ItemType.FILE || containsSymlinkChange(change)) { return false; } if (change.getChangeType().contains(ChangeType.ADD) || change.getChangeType().contains(ChangeType.BRANCH) || change.getChangeType().contains(ChangeType.DELETE)) { return false; } if (change.getChangeType().contains(ChangeType.RENAME) && !change.getChangeType().contains(ChangeType.EDIT)) { return false; } return true; }