/**
   * Writes the given AbstractDataTree to the given stream. This writes a single DataTree or
   * DeltaDataTree, ignoring parent trees.
   *
   * @param path Only writes data for the subtree rooted at the given path, and for all nodes
   *     directly between the root and the subtree.
   * @param depth In the subtree rooted at the given path, only write up to this depth. A depth of
   *     infinity is given by the constant D_INFINITE.
   */
  public void writeTree(AbstractDataTree tree, IPath path, int depth, DataOutput output)
      throws IOException {
    this.output = output;
    /* tunnel down relevant path */
    AbstractDataTreeNode node = tree.getRootNode();
    IPath currentPath = Path.ROOT;
    String[] segments = path.segments();
    for (int i = 0; i < segments.length; i++) {
      String nextSegment = segments[i];

      /* write this node to the output */
      writeSingleNode(node, currentPath);

      currentPath = currentPath.append(nextSegment);
      node = node.childAtOrNull(nextSegment);

      /* write the number of children for this node */
      if (node != null) {
        writeNumber(1);
      } else {
        /* can't navigate down the path, just give up with what we have so far */
        writeNumber(0);
        return;
      }
    }

    Assert.isTrue(currentPath.equals(path), "dtree.navigationError"); // $NON-NLS-1$

    /* recursively write the subtree we're interested in */
    writeNode(node, path, depth);
  }
  public boolean performFinish() {
    FeatureModel featureModel = new FeatureModel();
    featureModel.createDefaultValues("");

    Path fullFilePath = new Path(page.fileName.getText());
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IPath rootPath = root.getLocation();
    if (rootPath.isPrefixOf(fullFilePath)) {
      // case: is file in workspace
      int matchingFirstSegments = rootPath.matchingFirstSegments(fullFilePath);
      IPath localFilePath = fullFilePath.removeFirstSegments(matchingFirstSegments);
      String[] segments = localFilePath.segments();
      localFilePath = new Path("");
      for (String segment : segments) {
        localFilePath = localFilePath.append(segment);
      }
      IFile file = root.getFile(localFilePath);
      featureModel.initFMComposerExtension(file.getProject());
      try {
        new FeatureModelWriterIFileWrapper(new XmlFeatureModelWriter(featureModel))
            .writeToFile(file);
        file.refreshLocal(IResource.DEPTH_INFINITE, null);
      } catch (CoreException e) {
        FMUIPlugin.getDefault().logError(e);
      }
      open(file);
    } else {
      // case: is no file in workspace
      File file = fullFilePath.toFile();
      new XmlFeatureModelWriter(featureModel).writeToFile(file);
    }
    return true;
  }
示例#3
0
  /**
   * @param input
   * @return a tuple with the part name to be used and a boolean indicating if the maximum level has
   *     been reached for this path.
   */
  private Tuple<String, Boolean> getPartNameInLevel(
      int level,
      IPath path,
      String initHandling,
      String djangoModulesHandling,
      IEditorInput input) {
    String classStr = input.getClass().toString();
    if (classStr.endsWith("RemoteFileStoreEditorInput") && classStr.indexOf("com.aptana") != -1) {
      return new Tuple<String, Boolean>(input.getName(), true);
    }
    String[] segments = path.segments();
    if (segments.length == 0) {
      return new Tuple<String, Boolean>("", true);
    }
    if (segments.length == 1) {
      return new Tuple<String, Boolean>(segments[1], true);
    }
    String lastSegment = segments[segments.length - 1];

    boolean handled = isDjangoHandledModule(djangoModulesHandling, input, lastSegment);
    if (handled
        && djangoModulesHandling
            == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_SHOW_PARENT_AND_DECORATE) {
      String[] dest = new String[segments.length - 1];
      System.arraycopy(segments, 0, dest, 0, dest.length);
      segments = dest;

    } else if (initHandling != PyTitlePreferencesPage.TITLE_EDITOR_INIT_HANDLING_IN_TITLE) {
      if (lastSegment.startsWith("__init__.")) {
        // remove the __init__.
        String[] dest = new String[segments.length - 1];
        System.arraycopy(segments, 0, dest, 0, dest.length);
        segments = dest;
      }
    }

    int startAt = segments.length - level;
    if (startAt < 0) {
      startAt = 0;
    }

    int endAt = segments.length - 1;

    String modulePart = StringUtils.join(".", segments, startAt, endAt);

    String name = segments[segments.length - 1];
    if (!PyTitlePreferencesPage.getTitleShowExtension()) {
      String initial = name;
      name = FullRepIterable.getFirstPart(name);
      if (name.length() == 0) {
        name = initial;
      }
    }
    if (modulePart.length() > 0) {
      return new Tuple<String, Boolean>(name + " (" + modulePart + ")", startAt == 0);
    } else {
      return new Tuple<String, Boolean>(name, startAt == 0);
    }
  }
示例#4
0
 public static String getRelativePath(IPath filePath, IPath pathToGitRoot) {
   StringBuilder sb = new StringBuilder();
   String file = null;
   if (!filePath.hasTrailingSeparator()) {
     file = filePath.lastSegment();
     filePath = filePath.removeLastSegments(1);
   }
   for (int i = 0; i < pathToGitRoot.segments().length; i++) {
     if (pathToGitRoot.segments()[i].equals(".."))
       sb.append(
               filePath.segment(filePath.segments().length - pathToGitRoot.segments().length + i))
           .append("/");
     // else TODO
   }
   if (file != null) sb.append(file);
   return sb.toString();
 }
示例#5
0
 /**
  * Creates new folder from project root. The folder name can include relative path as a part of
  * the name. Nonexistent parent directories are being created.
  *
  * @param project - project where to create the folder.
  * @param name - folder name.
  * @return folder handle.
  * @throws CoreException if something goes wrong.
  */
 public static IFolder createFolder(IProject project, String name) throws CoreException {
   final IPath p = new Path(name);
   IContainer folder = project;
   for (String seg : p.segments()) {
     folder = folder.getFolder(new Path(seg));
     if (!folder.exists()) ((IFolder) folder).create(true, true, NULL_MONITOR);
   }
   resourcesCreated.add(folder);
   return (IFolder) folder;
 }
示例#6
0
 public IPath append(IPath path) {
   String[] inputSegs = path.segments();
   List<String> resultSegs = new ArrayList<String>(Arrays.asList(segments));
   for (String s : inputSegs) {
     if (s.equals(ELLIPSIS)) resultSegs.remove(resultSegs.size() - 1);
     else {
       resultSegs.add(s);
     }
   }
   return new URLPath(device, resultSegs.toArray(new String[0]), path.hasTrailingSeparator());
 }
 /**
  * Finds the template in the plug-in. Returns the template plug-in URI.
  *
  * @param bundleID is the plug-in ID
  * @param relativePath is the relative path of the template in the plug-in
  * @return the template URI
  * @throws IOException
  * @generated
  */
 @SuppressWarnings({"unused"})
 private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException {
   Bundle bundle = Platform.getBundle(bundleID);
   if (bundle == null) {
     // no need to go any further
     return URI.createPlatformResourceURI(
         new Path(bundleID).append(relativePath).toString(), false);
   }
   URL url = bundle.getEntry(relativePath.toString());
   if (url == null && relativePath.segmentCount() > 1) {
     Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true);
     if (entries != null) {
       String[] segmentsRelativePath = relativePath.segments();
       while (url == null && entries.hasMoreElements()) {
         URL entry = entries.nextElement();
         IPath path = new Path(entry.getPath());
         if (path.segmentCount() > relativePath.segmentCount()) {
           path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount());
         }
         String[] segmentsPath = path.segments();
         boolean equals = segmentsPath.length == segmentsRelativePath.length;
         for (int i = 0; equals && i < segmentsPath.length; i++) {
           equals = segmentsPath[i].equals(segmentsRelativePath[i]);
         }
         if (equals) {
           url = bundle.getEntry(entry.getPath());
         }
       }
     }
   }
   URI result;
   if (url != null) {
     result =
         URI.createPlatformPluginURI(
             new Path(bundleID).append(new Path(url.getPath())).toString(), false);
   } else {
     result =
         URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false);
   }
   return result;
 }
  private void createParents(IProject fragmentProject, IPath parent) throws CoreException {
    String[] segments = parent.segments();
    String path = new String();

    for (int i = 0; i < segments.length; i++) {
      path += SLASH + segments[i];
      IFolder folder = fragmentProject.getFolder(path);
      if (!folder.exists()) {
        folder.create(true, true, getProgressMonitor());
      }
    }
  }
  public ModelWorkspaceItem getWorkspaceItem(final IPath path, int resourceType) {
    CoreArgCheck.isNotNull(path);
    try {
      // first get all the projects
      ModelProject[] projects = getModelProjects();
      for (int i = 0; i < projects.length; i++) {
        ModelProject project = projects[i];
        if (resourceType == IResource.PROJECT) {
          if (project.getPath().equals(path)) {
            return project;
          }
        } else {
          if (!project.isOpen()) {
            continue;
          }

          // If the path only contains the project then we cannot match it
          // to a non-project type so return null
          if (path.segmentCount() < 2) {
            return null;
          }
          // If the first segment is not this project's name then skip it
          if (!path.segment(0).equals(project.getProject().getName())) {
            continue;
          }
          // Iterate over all the path segments navigating to the child by name
          ModelWorkspaceItem item = project;
          final String[] segments = path.segments();
          for (int j = 1; j < segments.length; j++) {
            final String segment = segments[j];
            if (!item.exists()) {
              // Must be in the process of closing (see defect 10957) ...
              return null;
            }
            item = item.getChild(segment);
            if (item == null) {
              break;
            } else if (item.getPath().makeRelative().equals(path.makeRelative())) {
              return item;
            }
          }
          // ModelWorkspaceItem[] children = project.getChildren();
          // return recursiveLookUp(children, path);
        }
      }
    } catch (ModelWorkspaceException e) {
      // do nothing
    }
    return null;
  }
  /**
   * Constructs path from the root of a build path to a module.
   *
   * @param modulePath - module path from root.
   * @return include path.
   */
  public static String constructPathFromRoot(IPath modulePath) {
    StringBuilder result = new StringBuilder();
    String[] segments = modulePath.segments();
    if (segments.length == 0) {
      return null;
    }

    for (int i = 0; i < segments.length - 1; i++) {
      result.append(segments[i]);
      result.append('/');
    }

    result.append(segments[segments.length - 1]);

    return result.toString();
  }
示例#11
0
 public IPath makeRelativeTo(IPath base) {
   int i = 0;
   String[] absolutePathSegs = segments();
   for (String seg : base.segments()) {
     if (!seg.equals(segment(i))) break;
     i++;
   }
   int ellipsisCount = base.segmentCount() - i;
   int remainedSegsCount = segmentCount() - i;
   StringBuilder sb = new StringBuilder();
   for (int j = 0; j < ellipsisCount + remainedSegsCount - 1; j++) {
     if (j < ellipsisCount) sb.append(ELLIPSIS + IPath.SEPARATOR);
     else sb.append(absolutePathSegs[i++] + IPath.SEPARATOR);
   }
   sb.append(absolutePathSegs[i]);
   return new URLPath(sb.toString());
 }
  /**
   * Constructs path from the root of a build path to a module.
   *
   * @param module - module.
   * @return include path.
   */
  private static String constructPathFromRoot(IModule module) {
    IPath path = module.getPath();
    StringBuilder result = new StringBuilder();
    String[] segments = path.segments();
    if (segments.length == 0) {
      return null;
    }

    for (int i = 0; i < segments.length - 1; i++) {
      result.append(segments[i]);
      result.append('/');
    }

    result.append(segments[segments.length - 1]);

    return result.toString();
  }
 /** @see org.teiid.designer.core.workspace.ModelWorkspace#findModelResource(IPath) */
 @Override
 public ModelResource findModelResource(final IPath pathInWorkspace) {
   CoreArgCheck.isNotNull(pathInWorkspace);
   try {
     ModelWorkspaceItem item = this;
     final String[] segments = pathInWorkspace.segments();
     for (int i = 0; i < segments.length; ++i) {
       final String segment = segments[i];
       if (item == null) {
         break;
       }
       item = item.getChild(segment);
     }
     if (item == null || item.getItemType() != ModelWorkspaceItem.MODEL_RESOURCE) {
       return null;
     }
     return (ModelResource) item;
   } catch (ModelWorkspaceException e) {
     ModelerCore.Util.log(e);
   }
   return null;
 }
示例#14
0
  /**
   * Recreates the data file from the given input path. In case the given path reflects a temporary
   * diagram file, it's path is used to recreate the data file, otherwise the given path is simply
   * made absolute and returned.
   *
   * @param inputPath the path to recreate the data file from
   * @return a file object representing the data file
   */
  public static IFile recreateDataFile(final IPath inputPath) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IProject project = root.getFile(inputPath).getProject();

    final int matchingSegments = project.getFullPath().matchingFirstSegments(inputPath);
    final int totalSegments = inputPath.segmentCount();
    final String extension = inputPath.getFileExtension();

    IFile result = null;

    if (totalSegments > matchingSegments) {
      // it shall be more than just the project

      IPath resultPath = null;

      if (ToscaUI.TOSCA_DIAGRAM_FILE_EXTENSION.equals(extension)) {
        // we got a temporary file here, so rebuild the file of the model from its path
        String originalExtension = inputPath.segment(matchingSegments);
        if (originalExtension.startsWith(".")) { // $NON-NLS-1$
          originalExtension = originalExtension.substring(1);
        }

        final String[] segments = inputPath.segments();
        IPath originalPath = project.getFullPath();
        for (int index = matchingSegments + 1; index < segments.length; ++index) {
          originalPath = originalPath.append(segments[index]);
        }

        resultPath = originalPath.removeFileExtension().addFileExtension(originalExtension);
      } else {
        resultPath = inputPath.makeAbsolute();
      }

      result = root.getFile(resultPath);
    }

    return result;
  }
示例#15
0
  /**
   * Returns or constructs a temporary folder for diagram files used as Graphiti editor input files.
   * The given path reflects the path where the original data file is located. The folder is
   * constructed in the project root named after the data file extension {@link
   * #DATA_FILE_EXTENSION_RAW}.
   *
   * @param dataFilePath path of the actual BPMN2 model file
   * @return an IFolder for the temporary folder.
   * @throws CoreException in case the folder could not be created.
   */
  public static IFolder getOrCreateTempFolder(final IPath dataFilePath) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    String name = dataFilePath.getFileExtension();
    if (name == null || name.length() == 0) {
      name = "tosca"; // $NON-NLS-1$
    }

    String dir = dataFilePath.segment(0);
    IFolder folder = root.getProject(dir).getFolder("." + name); // $NON-NLS-1$
    if (!folder.exists()) {
      folder.create(true, true, null);
    }
    String[] segments = dataFilePath.segments();
    for (int i = 1; i < segments.length - 1; i++) {
      String segment = segments[i];
      folder = folder.getFolder(segment);
      if (!folder.exists()) {
        folder.create(true, true, null);
      }
    }
    return folder;
  }
  /**
   * @param eObjectList
   * @return list of rest procedures
   */
  private static List<RestProcedure> findRestProcedures(ModelResource modelResource)
      throws Exception {
    List<RestProcedure> restfulProcedureArray = new ArrayList<RestProcedure>();
    Collection<EObject> eObjectList = modelResource.getEObjects();
    for (EObject eObject : eObjectList) {
      if (SqlAspectHelper.isProcedure(eObject)) {
        IPath path = ModelerCore.getModelEditor().getModelRelativePathIncludingModel(eObject);
        final StringBuffer sb = new StringBuffer();
        final String[] segments = path.segments();
        for (int i = 0; i < segments.length; i++) {
          if (i != 0) {
            sb.append('.');
          }
          final String segment = segments[i];
          sb.append(segment);
        }
        String fullName = sb.toString();
        String name = ((ProcedureImpl) eObject).getName();
        createRestProcedureCollection((Procedure) eObject, name, fullName, restfulProcedureArray);
      }
    }

    return restfulProcedureArray;
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object element) {
    IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) element;
    switch (entry.getType()) {
      case IRuntimeClasspathEntry.PROJECT:
        IResource res = entry.getResource();
        IJavaElement proj = JavaCore.create(res);
        if (proj == null) {
          return entry.getPath().lastSegment();
        } else {
          return lp.getText(proj);
        }
      case IRuntimeClasspathEntry.ARCHIVE:
        IPath path = entry.getPath();
        if (path == null) {
          return MessageFormat.format("Invalid path: {0}", new Object[] {"null"}); // $NON-NLS-1$
        }
        if (!path.isAbsolute() || !path.isValidPath(path.toString())) {
          return MessageFormat.format("Invalid path: {0}", new Object[] {path.toOSString()});
        }
        String[] segments = path.segments();
        StringBuffer displayPath = new StringBuffer();
        if (segments.length > 0) {
          String device = path.getDevice();
          if (device != null) {
            displayPath.append(device);
            displayPath.append(File.separator);
          }
          for (int i = 0; i < segments.length - 1; i++) {
            displayPath.append(segments[i]).append(File.separator);
          }
          displayPath.append(segments[segments.length - 1]);

          // getDevice means that's a absolute path.
          if (path.getDevice() != null && !path.toFile().exists()) {
            displayPath.append(" (missing) ");
          }
        } else {
          displayPath.append(path.toOSString());
        }
        return displayPath.toString();
      case IRuntimeClasspathEntry.VARIABLE:
        path = entry.getPath();
        IPath srcPath = entry.getSourceAttachmentPath();
        StringBuffer buf = new StringBuffer(path.toString());
        if (srcPath != null) {
          buf.append(" ["); // $NON-NLS-1$
          buf.append(srcPath.toString());
          IPath rootPath = entry.getSourceAttachmentRootPath();
          if (rootPath != null) {
            buf.append(IPath.SEPARATOR);
            buf.append(rootPath.toString());
          }
          buf.append(']');
        }
        // append JRE name if we can compute it
        if (path.equals(new Path(JavaRuntime.JRELIB_VARIABLE)) && fLaunchConfiguration != null) {
          try {
            IVMInstall vm = JavaRuntime.computeVMInstall(fLaunchConfiguration);
            buf.append(" - "); // $NON-NLS-1$
            buf.append(vm.getName());
          } catch (CoreException e) {
          }
        }
        return buf.toString();
      case IRuntimeClasspathEntry.CONTAINER:
        path = entry.getPath();
        if (fLaunchConfiguration != null) {
          try {
            IJavaProject project = null;
            try {
              project = JavaRuntime.getJavaProject(fLaunchConfiguration);
            } catch (CoreException e) {
            }
            if (project == null) {
            } else {
              IClasspathContainer container =
                  JavaCore.getClasspathContainer(entry.getPath(), project);
              if (container != null) {
                if (container.getDescription().startsWith("Persisted container")) {
                  return container.getPath().toString();
                } else {
                  return container.getDescription();
                }
              }
            }
          } catch (CoreException e) {
          }
        }
        return entry.getPath().toString();
      case IRuntimeClasspathEntry.OTHER:
        IRuntimeClasspathEntry delegate = entry;
        if (entry instanceof ClasspathEntry) {
          delegate = ((ClasspathEntry) entry).getDelegate();
        }
        String name = lp.getText(delegate);
        if (name == null || name.length() == 0) {
          return ((IRuntimeClasspathEntry2) delegate).getName();
        }
        return name;
    }
    return ""; //$NON-NLS-1$
  }
 public ModelWorkspaceItem getWorkspaceItem(final IPath path) {
   CoreArgCheck.isNotNull(path);
   try {
     // first get all the projects
     ModelProject[] projects = getModelProjects();
     for (int i = 0; i < projects.length; i++) {
       ModelProject project = projects[i];
       if (!project.exists()) {
         continue;
       }
       if (!project.isOpen()) {
         // See if the underlying project is open ...
         final IProject iproj = (IProject) project.getResource();
         if (!iproj.isOpen()) {
           continue;
         }
         // Try to open the ModelProject, since the IProject is open ...
         project.open(null);
         if (!project.isOpen()) {
           continue; // couldn't open it!
         }
       }
       if (project.getPath().equals(path)) {
         return project;
       }
       // Iterate over all the path segments navigating to the child by name
       ModelWorkspaceItem item = project;
       final String[] segments = path.segments();
       for (int j = 1; j < segments.length; j++) {
         final String segment = segments[j];
         if (!item.exists()) {
           // Must be in the process of closing (see defect 10957) ...
           return null;
         }
         final IResource itemResource = item.getResource();
         item = item.getChild(segment);
         if (item == null) {
           // May be a newly created IResource for which there is yet no ModelWorkspaceItem
           if (itemResource instanceof IContainer) {
             final IContainer itemContainer = (IContainer) itemResource;
             final IResource child = itemContainer.findMember(segment);
             if (child != null) {
               // Find the ModelWorkspaceItem ...
               item =
                   ModelWorkspaceManager.getModelWorkspaceManager()
                       .findModelWorkspaceItem(child, true);
             }
           }
         }
         if (item == null) {
           break;
         } else if (item.getPath().equals(path)) {
           return item;
         }
       }
     }
   } catch (ModelWorkspaceException e) {
     // do nothing
   }
   return null;
 }