/*
   * (non-Javadoc)
   *
   * @see
   * org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse
   * .jface.viewers.TreeViewer,
   * org.eclipse.jface.viewers.IStructuredSelection)
   */
  public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (factory.isUserReadOnlyOnCurrentProject()) {
      canWork = false;
    }
    if (canWork) {
      Object o = selection.getFirstElement();
      RepositoryNode node = (RepositoryNode) o;
      switch (node.getType()) {
        case REPOSITORY_ELEMENT:
          if (node.getObjectType() != CamelRepositoryNodeType.repositoryRouteResourceType) {
            canWork = false;
          } else {
            IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
            IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
            if (repFactory.isPotentiallyEditable(node.getObject())) {
              this.setText(""); // $NON-NLS-1$
            } else {
              this.setText(""); // $NON-NLS-1$
            }
          }
          break;
        default:
          canWork = false;
      }
      RepositoryNode parent = node.getParent();
      if (canWork && parent != null && parent instanceof BinRepositoryNode) {
        canWork = false;
      }
      if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
        canWork = false;
      }

      // If the editProcess action canwork is true, then detect that the
      // job version is the latest verison or not.
      if (canWork) {
        canWork = isLastVersion(node);
      }
    }
    setEnabled(canWork);

    this.setText("Open another version");
    this.setToolTipText("Open another version");
    this.setImageDescriptor(
        RouteResourceActivator.createImageDesc("icons/open-another-version.png"));
  }
 public IProxyRepositoryFactory getProxyRepositoryFactory() {
   IRepositoryService service = CoreRuntimePlugin.getInstance().getRepositoryService();
   return service.getProxyRepositoryFactory();
 }