Examples of RepositoryTreeNode


Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

      }
    }
  }

  private RepositoryTreeNode getNodeForPath(Repository repository, String repoRelativePath) {
    RepositoryTreeNode currentNode = null;
    ITreeContentProvider cp = (ITreeContentProvider) getCommonViewer()
        .getContentProvider();
    for (Object repo : cp.getElements(getCommonViewer().getInput())) {
      RepositoryTreeNode node = (RepositoryTreeNode) repo;
      // TODO equals implementation of Repository?
      if (repository.getDirectory().equals(
          ((Repository) node.getObject()).getDirectory())) {
        for (Object child : cp.getChildren(node)) {
          RepositoryTreeNode childNode = (RepositoryTreeNode) child;
          if (childNode.getType() == RepositoryTreeNodeType.WORKINGDIR) {
            currentNode = childNode;
            break;
          }
        }
        break;
      }
    }

    IPath relPath = new Path(repoRelativePath);

    for (String segment : relPath.segments())
      for (Object child : cp.getChildren(currentNode)) {
        @SuppressWarnings("unchecked")
        RepositoryTreeNode<File> childNode = (RepositoryTreeNode<File>) child;
        if (childNode.getObject().getName().equals(segment)) {
          currentNode = childNode;
          break;
        }
      }
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

  public StyledString getStyledText(Object element) {
    if (!(element instanceof RepositoryTreeNode))
      return null;

    RepositoryTreeNode node = (RepositoryTreeNode) element;

    switch (node.getType()) {
    case REPO:
      if (node.getParent() != null
          && node.getParent().getType() == RepositoryTreeNodeType.SUBMODULES)
        return getStyledTextForSubmodule(node);
      return GitLabels.getStyledLabelExtendedSafe(node.getObject());
    case ADDITIONALREF:
      Ref ref = (Ref) node.getObject();
      // shorten the name
      StyledString refName = new StyledString(
          Repository.shortenRefName(ref.getName()));

      ObjectId refId;
      if (ref.isSymbolic()) {
        refName.append(' ');
        refName.append('[', StyledString.DECORATIONS_STYLER);
        refName.append(ref.getLeaf().getName(),
            StyledString.DECORATIONS_STYLER);
        refName.append(']', StyledString.DECORATIONS_STYLER);
        refId = ref.getLeaf().getObjectId();
      } else
        refId = ref.getObjectId();

      refName.append(' ');
      RevCommit commit = getLatestCommit(node);
      if (commit != null)
        refName.append(abbreviate(commit),
            StyledString.QUALIFIER_STYLER)
            .append(' ')
            .append(commit.getShortMessage(),
                StyledString.QUALIFIER_STYLER);
      else
        refName.append(abbreviate(refId),
            StyledString.QUALIFIER_STYLER);
      return refName;
    case WORKINGDIR:
      StyledString dirString = new StyledString(
          UIText.RepositoriesView_WorkingDir_treenode);
      dirString.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
      dirString.append(node.getRepository().getWorkTree()
          .getAbsolutePath(), StyledString.QUALIFIER_STYLER);
      return dirString;

    case REF:
      StyledString styled = null;
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

  /**
   * @return the selected path
   */
  public String getPath() {
    IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
    RepositoryTreeNode node = (RepositoryTreeNode) sel.getFirstElement();
    if (node != null && node.getType() == RepositoryTreeNodeType.FOLDER)
      return ((File) node.getObject()).getPath();
    if (node != null && node.getType() == RepositoryTreeNodeType.WORKINGDIR)
      return node.getRepository().getWorkTree().getPath();
    return null;
  }
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

      tv.expandToLevel(2);
      // select the working directory as default
      if (initialPath == null)
        tv.setSelection(new StructuredSelection(input.get(0)));
      else {
        RepositoryTreeNode parentNode = node;

        IPath fullPath = new Path(initialPath);
        IPath workdirPath = new Path(initialRepository.getWorkTree()
            .getPath());
        if (workdirPath.isPrefixOf(fullPath)) {
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

    try {
      if (sel.isEmpty()) {
        setErrorMessage(UIText.GitImportWithDirectoriesPage_SelectFolderMessage);
        return;
      }
      RepositoryTreeNode node = (RepositoryTreeNode) sel
          .getFirstElement();
      if (node.getType() != RepositoryTreeNodeType.FOLDER
          && node.getType() != RepositoryTreeNodeType.WORKINGDIR) {
        setErrorMessage(UIText.GitImportWithDirectoriesPage_SelectFolderMessage);
        return;
      }
    } finally {
      setPageComplete(getErrorMessage() == null);
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

    // nothing
  }

  public Object[] getChildren(Object parentElement) {

    RepositoryTreeNode node = (RepositoryTreeNode) parentElement;
    Repository repo = node.getRepository();

    switch (node.getType()) {

    case BRANCHES: {
      List<RepositoryTreeNode> nodes = new ArrayList<RepositoryTreeNode>();
      nodes.add(new LocalNode(node, repo));
      nodes.add(new RemoteTrackingNode(node, repo));
      return nodes.toArray();
    }

    case LOCAL: {
      if (branchHierarchyMode) {
        BranchHierarchyNode hierNode = new BranchHierarchyNode(node,
            repo, new Path(Constants.R_HEADS));
        List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
        try {
          for (IPath path : hierNode.getChildPaths()) {
            children.add(new BranchHierarchyNode(node, node
                .getRepository(), path));
          }
          for (Ref ref : hierNode.getChildRefs()) {
            children.add(new RefNode(node, node.getRepository(),
                ref));
          }
        } catch (Exception e) {
          return handleException(e, node);
        }
        return children.toArray();
      } else {
        List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
        try {
          for (Entry<String, Ref> refEntry : getRefs(repo, Constants.R_HEADS).entrySet()) {
            if (!refEntry.getValue().isSymbolic())
              refs.add(new RefNode(node, repo, refEntry
                  .getValue()));
          }
        } catch (Exception e) {
          return handleException(e, node);
        }
        return refs.toArray();
      }
    }

    case REMOTETRACKING: {
      if (branchHierarchyMode) {
        BranchHierarchyNode hierNode = new BranchHierarchyNode(node,
            repo, new Path(Constants.R_REMOTES));
        List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
        try {
          for (IPath path : hierNode.getChildPaths()) {
            children.add(new BranchHierarchyNode(node, node
                .getRepository(), path));
          }
          for (Ref ref : hierNode.getChildRefs()) {
            children.add(new RefNode(node, node.getRepository(),
                ref));
          }
        } catch (Exception e) {
          return handleException(e, node);
        }
        return children.toArray();
      } else {
        List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
        try {
          for (Entry<String, Ref> refEntry : getRefs(repo, Constants.R_REMOTES).entrySet()) {
            if (!refEntry.getValue().isSymbolic())
              refs.add(new RefNode(node, repo, refEntry
                  .getValue()));
          }
        } catch (Exception e) {
          return handleException(e, node);
        }

        return refs.toArray();
      }
    }

    case BRANCHHIERARCHY: {
      BranchHierarchyNode hierNode = (BranchHierarchyNode) node;
      List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
      try {
        for (IPath path : hierNode.getChildPaths()) {
          children.add(new BranchHierarchyNode(node, node
              .getRepository(), path));
        }
        for (Ref ref : hierNode.getChildRefs()) {
          children.add(new RefNode(node, node.getRepository(), ref));
        }
      } catch (IOException e) {
        return handleException(e, node);
      }
      return children.toArray();
    }

    case TAGS: {
      return getTagsChildren(node, repo);
    }

    case ADDITIONALREFS: {
      List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
      try {
        for (Entry<String, Ref> refEntry : getRefs(repo, RefDatabase.ALL).entrySet()) {
          String name=refEntry.getKey();
          if (!(name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_TAGS)|| name.startsWith(Constants.R_REMOTES)))
            refs.add(new AdditionalRefNode(node, repo, refEntry
                .getValue()));
        }
        for (Ref r : repo.getRefDatabase().getAdditionalRefs())
          refs.add(new AdditionalRefNode(node, repo, r));
      } catch (Exception e) {
        return handleException(e, node);
      }
      return refs.toArray();
    }

    case REMOTES: {
      List<RepositoryTreeNode<String>> remotes = new ArrayList<RepositoryTreeNode<String>>();

      Repository rep = node.getRepository();

      Set<String> configNames = rep.getConfig().getSubsections(
          RepositoriesView.REMOTE);

      for (String configName : configNames) {
        remotes.add(new RemoteNode(node, repo, configName));
      }

      return remotes.toArray();
    }

    case REPO: {

      List<RepositoryTreeNode<? extends Object>> nodeList = new ArrayList<RepositoryTreeNode<? extends Object>>();
      nodeList.add(new BranchesNode(node, repo));
      nodeList.add(new TagsNode(node, repo));
      nodeList.add(new AdditionalRefsNode(node, repo));
      final boolean bare = repo.isBare();
      if (!bare)
        nodeList.add(new WorkingDirNode(node, repo));
      nodeList.add(new RemotesNode(node, repo));
      if(!bare && hasStashedCommits(repo))
        nodeList.add(new StashNode(node, repo));
      if (!bare && hasConfiguredSubmodules(repo))
        nodeList.add(new SubmodulesNode(node, repo));

      return nodeList.toArray();
    }

    case WORKINGDIR: {
      List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>();

      if (node.getRepository().isBare())
        return children.toArray();
      File workingDir = repo.getWorkTree();
      if (workingDir == null || !workingDir.exists())
        return children.toArray();

      File[] childFiles = workingDir.listFiles();
      Arrays.sort(childFiles, new Comparator<File>() {
        public int compare(File o1, File o2) {
          if (o1.isDirectory()) {
            if (o2.isDirectory()) {
              return o1.compareTo(o2);
            }
            return -1;
          } else if (o2.isDirectory()) {
            return 1;
          }
          return o1.compareTo(o2);
        }
      });
      for (File file : childFiles) {
        if (file.isDirectory()) {
          children.add(new FolderNode(node, repo, file));
        } else {
          children.add(new FileNode(node, repo, file));
        }
      }

      return children.toArray();
    }

    case FOLDER: {
      List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>();

      File parent = ((File) node.getObject());

      File[] childFiles = parent.listFiles();
      if (childFiles == null)
        return children.toArray();

      Arrays.sort(childFiles, new Comparator<File>() {
        public int compare(File o1, File o2) {
          if (o1.isDirectory()) {
            if (o2.isDirectory()) {
              return o1.compareTo(o2);
            }
            return -1;
          } else if (o2.isDirectory()) {
            return 1;
          }
          return o1.compareTo(o2);
        }
      });
      for (File file : childFiles) {
        if (file.isDirectory()) {
          children.add(new FolderNode(node, repo, file));
        } else {
          children.add(new FileNode(node, repo, file));
        }
      }

      return children.toArray();
    }

    case REMOTE: {

      List<RepositoryTreeNode<String>> children = new ArrayList<RepositoryTreeNode<String>>();

      String remoteName = (String) node.getObject();
      RemoteConfig rc;
      try {
        rc = new RemoteConfig(node.getRepository().getConfig(),
            remoteName);
      } catch (URISyntaxException e) {
        return handleException(e, node);
      }

      if (!rc.getURIs().isEmpty())
        children.add(new FetchNode(node, node.getRepository(), rc
            .getURIs().get(0).toPrivateString()));

      int uriCount = rc.getPushURIs().size();
      if (uriCount == 0 && !rc.getURIs().isEmpty())
        uriCount++;

      // show push if either a fetch or push URI is specified and
      // at least one push specification
      if (uriCount > 0) {
        URIish firstUri;
        if (!rc.getPushURIs().isEmpty())
          firstUri = rc.getPushURIs().get(0);
        else
          firstUri = rc.getURIs().get(0);

        if (uriCount == 1)
          children.add(new PushNode(node, node.getRepository(),
              firstUri.toPrivateString()));
        else
          children.add(new PushNode(node, node.getRepository(),
              firstUri.toPrivateString() + "...")); //$NON-NLS-1$
      }
      return children.toArray();

    }

    case SUBMODULES:
      List<RepositoryNode> children = new ArrayList<RepositoryNode>();
      try {
        SubmoduleWalk walk = SubmoduleWalk.forIndex(node
            .getRepository());
        while (walk.next()) {
          Repository subRepo = walk.getRepository();
          if (subRepo != null) {
            Repository cachedRepo = null;
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

    return null;
  }

  public boolean hasChildren(Object element) {
    // for some of the nodes we can optimize this call
    RepositoryTreeNode node = (RepositoryTreeNode) element;
    Repository repo = node.getRepository();
    switch (node.getType()) {
    case BRANCHES:
      return true;
    case REPO:
      return true;
    case ADDITIONALREFS:
      return true;
    case SUBMODULES:
      return true;
    case TAGS:
      try {
        return !getRefs(repo, Constants.R_TAGS).isEmpty();
      } catch (IOException e) {
        return true;
      }
    case WORKINGDIR:
      if (node.getRepository().isBare())
        return false;
      File workingDir = repo.getWorkTree();
      if (workingDir == null || !workingDir.exists())
        return false;
      return workingDir.listFiles().length > 0;
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

* Configures the Fetch
*/
public class ConfigureFetchCommand extends
    RepositoriesViewCommandHandler<RemoteNode> {
  public Object execute(ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode selectedNode = getFirstOrNull(getSelectedNodes(event));

    final String configName;
    if (selectedNode instanceof RemoteNode)
      configName = ((RemoteNode) selectedNode).getObject();
    else if (selectedNode instanceof FetchNode)
      configName = ((RemoteNode) selectedNode.getParent()).getObject();
    else
      return null;

    Dialog dlg = SimpleConfigureFetchDialog.getDialog(getShell(event),
        selectedNode.getRepository(), configName);
    dlg.open();
    return null;
  }
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

  }

  protected Collection<IPath> getSelectedFileAndFolderPaths(ExecutionEvent event) throws ExecutionException {
    Collection<IPath> paths = new ArrayList<IPath>();
    for (Object selectedNode : getSelectedNodes(event)) {
      RepositoryTreeNode treeNode = (RepositoryTreeNode) selectedNode;
      IPath path = treeNode.getPath();
      paths.add(path);
    }
    return paths;
  }
View Full Code Here

Examples of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode

* The user can override this suggestion.
*/
public class CreateBranchCommand extends
    RepositoriesViewCommandHandler<RepositoryTreeNode> {
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final RepositoryTreeNode node = getSelectedNodes(event).get(0);

    if (node.getType() == RepositoryTreeNodeType.ADDITIONALREF) {
      Ref ref = (Ref) node.getObject();
      try {
        RevCommit baseCommit = new RevWalk(node.getRepository())
            .parseCommit(ref.getLeaf().getObjectId());
        WizardDialog dlg = new WizardDialog(
            getShell(event),
            new CreateBranchWizard(node.getRepository(), baseCommit.name()));
        dlg.setHelpAvailable(false);
        dlg.open();
      } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
      }
      return null;
    }
    String base = null;
    if (node.getObject() instanceof Ref)
      base = ((Ref) node.getObject()).getName();
    new WizardDialog(getShell(event), new CreateBranchWizard(node
        .getRepository(), base)).open();
    return null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.