public static String getEditorID(IEditorInput input) throws PartInitException {
   Assert.isNotNull(input);
   IEditorDescriptor editorDescriptor;
   if (input instanceof IFileEditorInput) {
     editorDescriptor = IDE.getEditorDescriptor(((IFileEditorInput) input).getFile());
   } else {
     String name = input.getName();
     if (name == null) {
       throwPartInitException(DartEditorMessages.EditorUtility_could_not_find_editorId);
     }
     editorDescriptor = IDE.getEditorDescriptor(name);
   }
   return editorDescriptor.getId();
 }
    @Override
    public ImageDescriptor getImageDescriptor(Object object) {
      if (object instanceof IFileStore) {
        IFileStore fileStore = (IFileStore) object;

        try {
          if (fileStore.fetchInfo().isDirectory()) {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
          }

          IEditorDescriptor descriptor = IDE.getEditorDescriptor(fileStore.getName());

          if (descriptor != null) {
            return descriptor.getImageDescriptor();
          } else {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
          }
        } catch (PartInitException e) {

        }
      }

      return null;
    }
Esempio n. 3
0
 public void run() {
   try {
     if (element.getResource() instanceof IFile) {
       IFile file = (IFile) element.getResource();
       IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
       IDE.openEditor(page, file);
     } else {
       // 2012-04-13 sundl 添加处理引用包里的资源
       IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
       if (element instanceof ArchiveARESResource) {
         ArchiveARESResource aresfile = (ArchiveARESResource) element;
         ARESResourceEditorInput input = new ARESResourceEditorInput(aresfile);
         boolean active = OpenStrategy.activateOnOpen();
         try {
           IEditorDescriptor editor = IDE.getEditorDescriptor(aresfile.getElementName());
           if (editor != null) {
             IDE.openEditor(page, input, editor.getId(), active);
           }
         } catch (PartInitException e) {
           e.printStackTrace();
         }
       }
     }
   } catch (PartInitException e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
  public static String getEditorID(final IEditorInput input, final Object inputObject) {
    IEditorDescriptor editorDescriptor;
    try {
      if (input instanceof IFileEditorInput) {
        editorDescriptor = IDE.getEditorDescriptor(((IFileEditorInput) input).getFile());
      } else {
        editorDescriptor = IDE.getEditorDescriptor(input.getName());
      }
    } catch (final PartInitException e) {
      return null;
    }

    if (editorDescriptor != null) {
      return editorDescriptor.getId();
    }

    return null;
  }
 /** execute action on the file */
 protected void execute(IFile file, IAction action) {
   String conflictResourceLocalCopy =
       RegistryCheckInClientUtils.getConflictResourceServerCopy(file.getLocation().toOSString());
   IFile conflictFile =
       file.getWorkspace().getRoot().getFileForLocation(new Path(conflictResourceLocalCopy));
   try {
     IEditorDescriptor defaultEditor = IDE.getEditorDescriptor(file);
     IWorkbenchPage activePage =
         PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
     activePage.openEditor(new FileEditorInput(conflictFile), defaultEditor.getId());
   } catch (PartInitException e) {
     log.error(e);
   }
 }
 public IEditorPart openEditor(IWorkbenchPage page, IFile file, Item item, boolean forceReadOnly) {
   try {
     IEditorDescriptor editorDesc = IDE.getEditorDescriptor(file);
     RepositoryEditorInput repositoryEditorInput = new RepositoryEditorInput(file, item);
     repositoryEditorInput.setReadOnly(forceReadOnly);
     repositoryEditorInput.setRepositoryNode(null);
     IEditorPart editorPart = IDE.openEditor(page, repositoryEditorInput, editorDesc.getId());
     editors.put(editorPart, repositoryEditorInput);
     return editorPart;
   } catch (PartInitException e) {
     // e.printStackTrace();
     ExceptionHandler.process(e);
   }
   return null;
 }
  private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInEditor-IFile");
    try {

      if (file == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("FileName", file.getName());
      instrumentation.data("FilePath", file.getFullPath().toOSString());
      instrumentation.metric("activate", activate);

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc = IDE.getEditorDescriptor(file, true);

      String editorId = desc.getId();
      boolean isTooComplex = false;
      editorId = maybeSwapDefaultEditorDescriptor(editorId);
      if (DartUI.isTooComplexDartFile(file)) {
        isTooComplex = true;
        editorId = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
      }

      IEditorPart editor = IDE.openEditor(p, file, editorId, activate);
      if (isTooComplex) {
        DartUI.showTooComplexDartFileWarning(editor);
      }
      initializeHighlightRange(editor);
      return editor;
    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }
  /**
   * Opens the given file in the registered editor for the file type, or in the default text editor
   * if no editor is registered. This differs from the openInEditor() method in that the system
   * editor will never be opened.
   *
   * @param file the file to open
   * @return an open editor
   * @throws PartInitException if the editor could not be opened or the input element is not valid
   */
  public static IEditorPart openInTextEditor(IFile file, boolean activate)
      throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInTextEditor");
    try {

      if (file == null) {
        instrumentation.metric("Problem", "file is null");
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("FileName", file.getName());
      instrumentation.data("FilePath", file.getFullPath().toOSString());

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        instrumentation.metric("Problem", "no active workbench page");
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc = IDE.getEditorDescriptor(file, true);

      if (desc.getId() == IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID) {
        IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();

        desc = editorReg.findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID);
      }

      IEditorPart editorPart =
          IDE.openEditor(p, file, maybeSwapDefaultEditorDescriptor(desc.getId()), activate);
      initializeHighlightRange(editorPart);
      return editorPart;

    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }
  /**
   * Guesses the function effected/modified by the patch from local file(newer file).
   *
   * @param patchFileInfo patch file
   * @return array of unique function names
   */
  private String[] guessFunctionNames(PatchFile patchFileInfo) {

    // if this file is new file or removed file, do not guess function files
    // TODO: create an option to include function names on
    // new files or not
    if (patchFileInfo.isNewfile() || patchFileInfo.isRemovedFile()) {
      return new String[] {""};
    }

    String[] fnames = new String[0];
    String editorName = ""; // $NON-NLS-1$

    try {
      IEditorDescriptor ed =
          org.eclipse.ui.ide.IDE.getEditorDescriptor(patchFileInfo.getPath().toOSString());
      editorName = ed.getId().substring(ed.getId().lastIndexOf(".") + 1); // $NON-NLS-1$
    } catch (PartInitException e1) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e1.getMessage(), e1));
      return new String[0];
    }

    // check if the file type is supported

    // get editor input for target file

    IFileEditorInput fei = new FileEditorInput((IFile) patchFileInfo.getResource());

    SourceEditorInput sei = new SourceEditorInput(patchFileInfo.getStorage());

    MyDocumentProvider mdp = new MyDocumentProvider();
    MyStorageDocumentProvider msdp = new MyStorageDocumentProvider();

    try {
      // get document for target file (one for local file, one for repository storage)
      IDocument doc = mdp.createDocument(fei);
      IDocument olddoc = msdp.createDocument(sei);

      HashMap<String, String> functionNamesMap = new HashMap<String, String>();
      ArrayList<String> nameList = new ArrayList<String>();

      // for all the ranges
      for (PatchRangeElement tpre : patchFileInfo.getRanges()) {

        for (int j = tpre.ffromLine; j <= tpre.ftoLine; j++) {

          String functionGuess = "";
          // add func that determines type of file.
          // right now it assumes it's java file.
          if (tpre.isLocalChange()) {
            if ((j < 0) || (j > doc.getNumberOfLines() - 1)) continue; // ignore out of bound lines
            functionGuess = parseCurrentFunctionAtOffset(editorName, fei, doc.getLineOffset(j));
          } else {
            if ((j < 0) || (j > olddoc.getNumberOfLines() - 1))
              continue; // ignore out of bound lines
            functionGuess = parseCurrentFunctionAtOffset(editorName, sei, olddoc.getLineOffset(j));
          }

          // putting it in hashmap will eliminate duplicate
          // guesses.  We use a list to keep track of ordering which
          // is helpful when trying to document a large set of changes.
          if (functionNamesMap.get(functionGuess) == null) nameList.add(functionGuess);
          functionNamesMap.put(functionGuess, functionGuess);
        }
      }

      // dump all unique func. guesses in the order found
      fnames = new String[nameList.size()];
      fnames = nameList.toArray(fnames);

    } catch (CoreException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    } catch (BadLocationException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    } catch (Exception e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
      e.printStackTrace();
    }
    return fnames;
  }