private boolean isTemporarilyUnfilteredInternal(Object parent) {
   if (parent instanceof TreePath) {
     TreePath treePath = (TreePath) parent;
     parent = treePath.getLastSegment();
   }
   return temporarilyUnfiltered != null && temporarilyUnfiltered.equals(parent);
 }
  @SuppressWarnings({"unchecked", "rawtypes"})
  private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
    if (!(selection instanceof ITreeSelection)) return EMPTY_WORKING_SET_ARRAY;

    ITreeSelection treeSelection = (ITreeSelection) selection;
    if (treeSelection.isEmpty()) return EMPTY_WORKING_SET_ARRAY;

    List elements = treeSelection.toList();
    if (elements.size() == 1) {
      Object element = elements.get(0);
      TreePath[] paths = treeSelection.getPathsFor(element);
      if (paths.length != 1) return EMPTY_WORKING_SET_ARRAY;

      TreePath path = paths[0];
      if (path.getSegmentCount() == 0) return EMPTY_WORKING_SET_ARRAY;

      Object candidate = path.getSegment(0);
      if (!(candidate instanceof IWorkingSet)) return EMPTY_WORKING_SET_ARRAY;

      IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
      if (isValidWorkingSet(workingSetCandidate)) return new IWorkingSet[] {workingSetCandidate};

      return EMPTY_WORKING_SET_ARRAY;
    }

    ArrayList result = new ArrayList();
    for (Iterator iterator = elements.iterator(); iterator.hasNext(); ) {
      Object element = iterator.next();
      if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) {
        result.add(element);
      }
    }
    return (IWorkingSet[]) result.toArray(new IWorkingSet[result.size()]);
  }
  /**
   * 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());
  }
 @Test
 public void headPathShouldReturnTheCorrectSubPath() {
   TreePath path = new TreePath(new Object[] {"a", "b", "c"});
   TreePath expected = path.getParentPath();
   TreePath actual = TreePaths.headPath(path, path.getSegmentCount() - 1);
   assertThat(actual, equalTo(expected));
 }
  /**
   * 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 Object internalGetElement(Object elementOrPath) {
   if (elementOrPath instanceof TreePath) {
     TreePath tp = (TreePath) elementOrPath;
     return tp.getLastSegment();
   }
   return elementOrPath;
 }
 public void init(IWorkbench workbench, IStructuredSelection selection) {
   if (selection instanceof TreeSelection) {
     try {
       TreeSelection treeSelection = (TreeSelection) selection;
       for (TreePath path : treeSelection.getPaths()) {
         for (int i = 0; i < path.getSegmentCount(); i++) {
           Object obj = path.getSegment(i);
           if (obj instanceof Category<?>) {
             setLighthouseDomain(((Category<?>) obj).getLighthouseDomain());
           }
           if (obj instanceof Operation) {
             addOperation((Operation) obj);
           }
           if (obj instanceof LighthouseDomain) {
             setLighthouseDomain((LighthouseDomain) obj);
           }
           if (obj instanceof Deployment) {
             addDeployment((Deployment) obj);
           }
         }
       }
       if (treeSelection.getPaths().length == 0
           || (selectedDeployments == null && selectedOperations == null)) {
         tryToInitFromActiveEditor();
       }
     } catch (Exception e) {
       OperationsUI.getPlugin()
           .getLog()
           .log(new Status(IStatus.ERROR, OperationsUI.PLUGIN_ID, e.getMessage(), e));
     }
   } else {
     tryToInitFromActiveEditor();
   }
 }
예제 #8
0
 /**
  * Recursively searches the VMC for Launch VMC, and returns its ILaunch. Returns null if an
  * ILaunch is not found.
  */
 private ILaunch findLaunch(TreePath path) {
   for (int i = path.getSegmentCount() - 1; i >= 0; i--) {
     if (path.getSegment(i) instanceof ILaunch) {
       return (ILaunch) path.getSegment(i);
     }
   }
   return null;
 }
 private Object[] internalGetChildren(
     ISynchronizationContext context, Object parent, Object[] children) {
   List result = new ArrayList(children.length);
   for (int i = 0; i < children.length; i++) {
     Object object = children[i];
     // If the parent is a TreePath then the subclass is
     // TreePath aware and we can send a TrePath to the
     // isVisible method
     if (parent instanceof TreePath) {
       TreePath tp = (TreePath) parent;
       object = tp.createChildPath(object);
     }
     if (isVisible(context, object)) result.add(internalGetElement(object));
   }
   return result.toArray(new Object[result.size()]);
 }
예제 #10
0
 /**
  * helper to create element format settings for all children paths of a given element path. Tree
  * paths at the same level will use the same format. Tree paths at different levels will use
  * different formats.
  *
  * @param _viewer tree viewer
  * @param path given element path
  * @param formats formats to rotate for different levels of children tree paths
  * @param levelStop depth to stop recursively walk down the children.
  * @param levelIndex index to a format for a level of children
  * @param result store the created element format settings
  */
 void makeElementFormatSetting(
     ITreeModelViewer _viewer,
     TreePath path,
     String[] formats,
     int levelStop,
     int levelIndex,
     HashMap<String, ElementFormatSetting> result) {
   if (levelStop >= 0 && levelIndex >= levelStop) return;
   IInternalTreeModelViewer viewer = (IInternalTreeModelViewer) _viewer;
   int childCount = viewer.getChildCount(path);
   if (childCount == 0) return;
   String fmt = formats[levelIndex % formats.length];
   ElementFormatSetting setting = result.get(fmt);
   if (setting == null) {
     setting = new ElementFormatSetting();
     setting.nodes = new ArrayList<IVMNode>(childCount);
     setting.elementPaths = new ArrayList<TreePath>(childCount);
     setting.formatId = fmt;
     result.put(fmt, setting);
   }
   for (int i = 0; i < childCount; i++) {
     Object viewerObject = viewer.getChildElement(path, i);
     if (viewerObject instanceof TestElementVMContext) {
       TreePath childPath = path.createChildPath(viewerObject);
       setting.nodes.add(((TestElementVMContext) viewerObject).getVMNode());
       setting.elementPaths.add(childPath);
       makeElementFormatSetting(viewer, childPath, formats, levelStop, levelIndex + 1, result);
     }
   }
 }
 /** @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));
 }
예제 #12
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();
 }
 /** @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);
 }
예제 #16
0
  private void doDoubleClick() {
    MassifViewPart view = (MassifViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    MassifTreeViewer treeViewer = view.getTreeViewer();

    MassifSnapshot[] snapshots = view.getSnapshots();
    node = snapshots[1].getRoot(); // first detailed
    TreePath path = new TreePath(new Object[] {node});
    while (node.getChildren().length > 0 && !node.hasSourceFile()) {
      node = node.getChildren()[0];
      path = path.createChildPath(node);
    }
    if (node.hasSourceFile()) {
      treeViewer.getViewer().expandToLevel(node, TreeViewer.ALL_LEVELS);
      TreeSelection selection = new TreeSelection(path);

      // do double click
      IDoubleClickListener listener = treeViewer.getDoubleClickListener();
      listener.doubleClick(new DoubleClickEvent(treeViewer.getViewer(), selection));
    } else {
      fail();
    }
  }
 @Test
 public void headPathShouldThrowAnExceptionIfIndexIsGreaterThanThePathLength() {
   TreePath path = newPath();
   thrown.expect(IllegalArgumentException.class);
   TreePaths.headPath(path, path.getSegmentCount() + 1);
 }
 @Test
 public void headPathShouldReturnAnEqualPathIfIndexIsEqualToThePathLength() {
   TreePath path = newPath();
   assertThat(TreePaths.headPath(path, path.getSegmentCount()), equalTo(path));
 }
 @Override
 public Object[] getChildren(TreePath parentPath) {
   return getChildren(parentPath.getLastSegment());
 }
  /**
   * the command has been executed, so extract extract the needed information from the application
   * context.
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    IWorkbenchPage activePage = window.getActivePage();
    ISelection selection = activePage.getSelection();
    if (selection != null && selection instanceof ITreeSelection) {
      TreeSelection treeSelection = (TreeSelection) selection;
      TreePath[] treePaths = treeSelection.getPaths();
      TreePath treePath = treePaths[0];

      Object firstSegmentObj = treePath.getFirstSegment();

      IProject project = (IProject) ((IAdaptable) firstSegmentObj).getAdapter(IProject.class);
      String workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
      File projectDir = new File(workspacePath + File.separator + project.getName());

      // System.out.println("FireFox path: " + WebCLSDKPreferencePage.getFirefoxPath());
      // "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
      String nodejsPath = WebCLSDKPreferencePage.getNodeJSPath();
      if (nodejsPath == null || nodejsPath.isEmpty()) {
        MessageDialog.openWarning(
            window.getShell(),
            "High Web Warning - NodeJS Path",
            "NodeJS 경로가 세팅되어 있지 않습니다.\n"
                + "Window - Preferences - High Web Tool 에서 NodeJS 경로를 세팅해 주세요");
        return null;
      }

      String defaultWebBrwoserRegKey = "";
      try {
        defaultWebBrwoserRegKey =
            Utils.WindowsRegistry.getKeySz(
                Utils.WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Mozilla\\Firefox", "");
      } catch (java.util.prefs.BackingStoreException e) {
        try {
          defaultWebBrwoserRegKey =
              Utils.WindowsRegistry.getKeySz(
                  Utils.WindowsRegistry.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\Firefox", "");
        } catch (java.util.prefs.BackingStoreException e1) {
          MessageDialog.openWarning(
              window.getShell(),
              "High Web Warning - Mozilla Firefox Installation",
              "Mozilla Firefox 브라우저가 설치되어 있지 않습니다.\n"
                  + "Mozilla Firefox 3.3 버전 및 Nokia WebCL Extension을 설치해 주세요");
          return null;
        }
      }

      String firefoxPath = WebCLSDKPreferencePage.getFirefoxPath();
      if (firefoxPath == null || firefoxPath.isEmpty()) {
        MessageDialog.openWarning(
            window.getShell(),
            "High Web Warning - Firefox Path",
            "Firefox 경로가 세팅되어 있지 않습니다.\n"
                + "Window - Preferences - High Web Tool 에서 Firefox 경로를 세팅해 주세요");
        return null;
      }

      ProcessBuilder pBuilder = null;

      try {
        String progFilesx86Dir = System.getenv("ProgramFiles(x86)");
        String helper =
            progFilesx86Dir
                + File.separator
                + "Mozilla Firefox"
                + File.separator
                + "uninstall"
                + File.separator
                + "helper.exe";
        pBuilder = new ProcessBuilder(new String[] {helper, "/SetAsDefaultAppUser"});
        pBuilder.redirectErrorStream(true);
        Process proc = pBuilder.start();
        proc.waitFor();
      } catch (Exception e) {
        e.printStackTrace();
      }

      try {
        Process proc = null;
        if (Activator.nodejsProcess != null && Activator.nodejsProcess.isAlive()) {
          String url = "http://localhost:4400/?enableripple=true";
          pBuilder = new ProcessBuilder(new String[] {firefoxPath, url});
          pBuilder.redirectErrorStream(true);
          proc = pBuilder.start();
        } else {
          String webContentPath = projectDir.getAbsolutePath() + File.separator + "WebContent";
          String appdata = System.getenv("APPDATA");
          String ripple =
              appdata
                  + File.separator
                  + "npm"
                  + File.separator
                  + "node_modules"
                  + File.separator
                  + "ripple-emulator"
                  + File.separator
                  + "bin"
                  + File.separator
                  + "ripple";
          String rippleArg = "emulate";
          pBuilder = new ProcessBuilder(new String[] {nodejsPath, ripple, rippleArg});
          pBuilder.redirectErrorStream(true);
          pBuilder.directory(new File(webContentPath));
          proc = pBuilder.start();
          Activator.nodejsProcess = proc;
        }
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return null;
  }