private ISelection restoreSelectionState(IMemento memento) {
    if (memento == null) return null;

    IMemento childMem;
    childMem = memento.getChild(TAG_SELECTED_ELEMENTS);
    if (childMem != null) {
      ArrayList list = new ArrayList();
      IMemento[] elementMem = childMem.getChildren(TAG_SELECTED_ELEMENT);
      for (int i = 0; i < elementMem.length; i++) {
        String javaElementHandle = elementMem[i].getString(TAG_SELECTED_ELEMENT_PATH);
        if (javaElementHandle == null) {
          // logical package
          IMemento[] packagesMem = elementMem[i].getChildren(TAG_LOGICAL_PACKAGE);
          LogicalPackage lp = null;
          for (int j = 0; j < packagesMem.length; j++) {
            javaElementHandle = packagesMem[j].getString(TAG_SELECTED_ELEMENT_PATH);
            Object pack = DLTKCore.create(javaElementHandle);
            if (pack instanceof IScriptFolder && ((IScriptFolder) pack).exists()) {
              if (lp == null) lp = new LogicalPackage((IScriptFolder) pack);
              else lp.add((IScriptFolder) pack);
            }
          }
          if (lp != null) list.add(lp);
        } else {
          IModelElement element = DLTKCore.create(javaElementHandle);
          if (element != null && element.exists()) list.add(element);
        }
      }
      return new StructuredSelection(list);
    }
    return null;
  }
Ejemplo n.º 2
0
 private String formatLogicalPackageMessage(LogicalPackage logicalPackage) {
   IScriptFolder[] fragments = logicalPackage.getScriptFolders();
   StringBuffer buf = new StringBuffer(logicalPackage.getElementName());
   buf.append(ScriptElementLabels.CONCAT_STRING);
   String message = ""; // $NON-NLS-1$
   boolean firstTime = true;
   for (int i = 0; i < fragments.length; i++) {
     IScriptFolder fragment = fragments[i];
     IModelElement element = fragment.getParent();
     if (element instanceof IProjectFragment) {
       IProjectFragment root = (IProjectFragment) element;
       String label =
           ScriptElementLabels.getDefault()
               .getElementLabel(
                   root,
                   ScriptElementLabels.DEFAULT_QUALIFIED | ScriptElementLabels.ROOT_QUALIFIED);
       if (firstTime) {
         buf.append(label);
         firstTime = false;
       } else
         message =
             Messages.format(
                 ScriptBrowsingMessages.StatusBar_concat, new String[] {message, label});
     }
   }
   buf.append(message);
   return buf.toString();
 }
Ejemplo n.º 3
0
  void adjustInputAndSetSelection(Object o) {
    if (!(o instanceof LogicalPackage)) {
      super.adjustInputAndSetSelection(o);
      return;
    }

    LogicalPackage lp = (LogicalPackage) o;
    if (!lp.getScriptProject().equals(getInput())) setInput(lp.getScriptProject());

    setSelection(new StructuredSelection(lp), true);
  }
  /**
   * Combines packages with same names into a logical package which will be added to the resulting
   * array. If a package is not yet in this content provider then the package fragment is added to
   * the resulting array.
   *
   * @param packageFragments the package fragments to combine
   * @return an array with combined (logical) packages and package fragments
   */
  protected Object[] combineSamePackagesIntoLogialPackages(IPackageFragment[] packageFragments) {

    if (!fCompoundState) return packageFragments;

    List newChildren = new ArrayList();

    for (int i = 0; i < packageFragments.length; i++) {
      IPackageFragment fragment = packageFragments[i];

      if (fragment == null) continue;

      LogicalPackage lp = findLogicalPackage(fragment);

      if (lp != null) {
        if (lp.belongs(fragment)) {
          lp.add(fragment);
        }
        if (!newChildren.contains(lp)) newChildren.add(lp);

      } else {
        String key = getKey(fragment);
        IPackageFragment frag = (IPackageFragment) fMapToPackageFragments.get(key);
        if (frag != null && !fragment.equals(frag)) {
          lp = new LogicalPackage(frag);
          lp.add(fragment);
          newChildren.remove(frag);
          newChildren.add(lp);
          fMapToLogicalPackage.put(key, lp);
          fMapToPackageFragments.remove(frag);
        } else {
          fMapToPackageFragments.put(key, fragment);
          newChildren.add(fragment);
        }
      }
    }
    return newChildren.toArray();
  }