/**
   * Returns a valid instance selection for the current selection of the tree viewer. Returns <code>
   * null</code> if there is none.
   *
   * @return a valid instance selection for the current selection of the tree viewer or <code>null
   *     </code>
   */
  private InstanceSelection getValidSelection() {
    ISelection viewerSelection = treeViewer.getSelection();
    if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty()) return null;

    ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
    TreePath firstPath = treeSelection.getPaths()[0]; // XXX use all paths
    // instead of first
    // only?

    InstanceValidationMessage firstMessage;
    Iterator<InstanceValidationMessage> restIter;

    if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
      firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
      restIter = Iterators.emptyIterator();
    } else {
      Collection<InstanceValidationMessage> messages =
          contentProvider.getMessages(treeSelection.getPaths()[0]);
      if (messages.isEmpty()) return null; // shouldn't happen, but doesn't really matter
      restIter = messages.iterator();
      firstMessage = restIter.next();
    }

    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    // check first message for valid instance reference
    if (firstMessage.getInstanceReference() == null
        || is.getInstance(firstMessage.getInstanceReference()) == null) return null;

    Set<InstanceReference> references = new HashSet<InstanceReference>();
    references.add(firstMessage.getInstanceReference());
    while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());

    return new DefaultInstanceSelection(references.toArray());
  }
 private Object internalGetElement(Object elementOrPath) {
   if (elementOrPath instanceof TreePath) {
     TreePath tp = (TreePath) elementOrPath;
     return tp.getLastSegment();
   }
   return elementOrPath;
 }
  /**
   * Changes the state of the TransformationView according to the currently selected shape
   *
   * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent event)
   */
  @Override
  public void selectionChanged(SelectionChangedEvent event) {

    // Get the TransformationView if it is open

    TransformationView transformationView =
        (TransformationView) workbenchPage.findView(TransformationView.ID);

    // Return if not

    if (transformationView == null) {
      return;
    }
    // Get the tree paths

    ITreeSelection selection = (ITreeSelection) event.getSelection();
    TreePath[] paths = selection.getPaths();

    // Remove the "selected" value from previously selected shapes

    for (IShape shape : selectedShapes) {
      shape.removeProperty("selected");
    }

    selectedShapes.clear();

    // Set the "selected" value to true for newly selected shapes

    for (TreePath path : paths) {
      Object selectedObject = path.getLastSegment();

      // Only perform the action for selected IShapes
      // (rather than GeometryComponents or null)

      if (selectedObject instanceof IShape) {
        IShape selectedShape = (IShape) selectedObject;

        selectedShape.setProperty("selected", "true");
        selectedShapes.add(selectedShape);
      }
    }

    // Set the TransformationView shape to null if nothing is selected
    // or there are multiple selections

    if (paths.length != 1) {
      transformationView.setShape(null);
      return;
    }

    Object selectedObject = paths[0].getLastSegment();

    // Determine if the shape of the TransformationView should be set

    if (selectedObject instanceof IShape) {
      transformationView.setShape((IShape) selectedObject);
    } else {
      transformationView.setShape(null);
    }
  }
 private boolean isTemporarilyUnfilteredInternal(Object parent) {
   if (parent instanceof TreePath) {
     TreePath treePath = (TreePath) parent;
     parent = treePath.getLastSegment();
   }
   return temporarilyUnfiltered != null && temporarilyUnfiltered.equals(parent);
 }
 /** @generated */
 public void updateLabel(ViewerLabel label, TreePath elementPath) {
   Object element = elementPath.getLastSegment();
   if (element instanceof TOENavigatorItem && !isOwnView(((TOENavigatorItem) element).getView())) {
     return;
   }
   label.setText(getText(element));
   label.setImage(getImage(element));
 }
 /** @generated */
 @Override
 public void updateLabel(ViewerLabel label, TreePath elementPath) {
   Object element = elementPath.getLastSegment();
   if (element instanceof BreezeModel.diagram.navigator.BreezeNavigatorItem
       && !this.isOwnView(
           ((BreezeModel.diagram.navigator.BreezeNavigatorItem) element).getView())) {
     return;
   }
   label.setText(this.getText(element));
   label.setImage(this.getImage(element));
 }
 /** @generated */
 public void updateLabel(ViewerLabel label, TreePath elementPath) {
   Object element = elementPath.getLastSegment();
   if (element instanceof hub.top.adaptiveSystem.diagram.navigator.AdaptiveSystemNavigatorItem
       && !isOwnView(
           ((hub.top.adaptiveSystem.diagram.navigator.AdaptiveSystemNavigatorItem) element)
               .getView())) {
     return;
   }
   label.setText(getText(element));
   label.setImage(getImage(element));
 }
 @Override
 protected String getLabel(TreePath elementPath, IPresentationContext context, String columnId)
     throws CoreException {
   if (columnId == null) {
     // when no columns, handle special escaping ourselves
     IDebugModelPresentation presentation = getCeylonJDIModelPresentation();
     if (presentation != null) {
       return presentation.getText(elementPath.getLastSegment());
     }
   }
   return super.getLabel(elementPath, context, columnId);
 }
Exemplo n.º 9
0
 public void selectionChanged(SelectionChangedEvent event) {
   Object selection = ((TreeSelection) event.getSelection()).getFirstElement();
   clearInfoPanel();
   if (selection instanceof IFile) {
     TreePath tp =
         (TreePath)
             ((TreeSelection) event.getSelection()).getPathsFor(selection)[0].getParentPath();
     TreeProject treeProject = (TreeProject) (tp.getLastSegment());
     editor =
         new ModePropertyEditorComposite(
             getInfoPanel(), treeProject.java_project, (IFile) selection);
   } else {
     editor = null;
     new VJPInfoComposite(getInfoPanel(), SWT.NULL);
   }
   refreshInfoPanel();
 }
 @Override
 public Object[] getChildren(TreePath parentPath) {
   return getChildren(parentPath.getLastSegment());
 }