public void run(IProgressMonitor progressMonitor)
      throws InvocationTargetException, InterruptedException {
    try {
      boolean isFixedForm = getFortranEditor().isFixedForm();

      IDocument doc = getFortranEditor().getIDocument();
      Reader in = new StringReader(doc.get());
      Reader cppIn = new CPreprocessingReader(getFortranEditor().getIFile(), null, in);
      try {
        File tempFile =
            File.createTempFile(
                "tmp", //$NON-NLS-1$
                isFixedForm ? ".f" : ".f90"); // $NON-NLS-1$ //$NON-NLS-2$
        tempFile.deleteOnExit();
        PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(tempFile)));
        try {
          for (int c = cppIn.read(); c != -1; c = cppIn.read()) out.print((char) c);
        } finally {
          out.close();
        }

        IDE.openEditor(
            Workbench.getInstance().getActiveWorkbenchWindow().getActivePage(),
            tempFile.toURI(),
            FortranEditor.EDITOR_ID,
            true);
      } finally {
        cppIn.close();
      }
    } catch (Exception e) {
      String message = e.getMessage();
      if (message == null) message = e.getClass().getName();
      MessageDialog.openError(getFortranEditor().getShell(), "Error", message); // $NON-NLS-1$
    }
  }
  /**
   * Given a <code>file</code> get an editor for it. If an editor has already been retrieved for the
   * given <code>file</code> then return the same already open editor.
   *
   * <p>When opening the editor it will also standardized the line endings to <code>\n</code>
   *
   * @param file open and return an editor for this
   * @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
   */
  public AbstractTextEditor getEditor(IFile file) {
    AbstractTextEditor editor = (AbstractTextEditor) fFileToEditorMap.get(file);

    if (editor == null) {
      try {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        IEditorPart editorPart = null;
        if (file.getFileExtension().equals("js")) {
          editorPart = IDE.openEditor(page, file, true, true);
        } else if (file.getFileExtension().equals("html")) {
          editorPart =
              IDE.openEditor(page, file, "org.eclipse.wst.html.core.htmlsource.source", true);
        }

        if (editorPart instanceof AbstractTextEditor) {
          editor = (AbstractTextEditor) editorPart;
        } else {
          Assert.fail("Unable to open structured text editor");
        }

        if (editor != null) {
          standardizeLineEndings(editor);
          fFileToEditorMap.put(file, editor);
        } else {
          Assert.fail("Could not open editor for " + file);
        }
      } catch (Exception e) {
        Assert.fail("Could not open editor for " + file + " exception: " + e.getMessage());
      }
    }

    return editor;
  }
示例#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();
   }
 }
  /** Test that an editor notifies reconciling listeners when the editor gets focus. */
  public void testFocusedReconciling() throws Exception {
    IFile file = getOrCreateFile(PROJECT_NAME + "/" + "focustest.xml");
    IFile fileAlt = getOrCreateFile(PROJECT_NAME + "/" + "focustestAlt.xml");
    IWorkbenchPage activePage =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final int[] state = new int[2];
    Arrays.fill(state, -1);
    ISourceReconcilingListener listener =
        new ISourceReconcilingListener() {
          int mod = 0;

          public void reconciled(
              IDocument document,
              IAnnotationModel model,
              boolean forced,
              IProgressMonitor progressMonitor) {
            state[1] = mod++;
          }

          public void aboutToBeReconciled() {
            state[0] = mod++;
          }
        };
    IEditorPart editor =
        IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
    try {
      assertTrue("Not a StructuredTextEditor", editor instanceof StructuredTextEditor);
      addReconcilingListener((StructuredTextEditor) editor, listener);
      waitForReconcile(state);
      assertTrue(
          "Initial: Reconciling did not complete in a timely fashion",
          state[0] != -1 && state[1] != -1);
      assertTrue(
          "Initial: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 0);
      assertTrue(
          "Initial: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")",
          state[1] == 1);
      IDE.openEditor(activePage, fileAlt, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
      Arrays.fill(state, -1);
      IEditorPart editorPart =
          IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
      assertEquals("Didn't get the original editor back.", editor, editorPart);
      waitForReconcile(state);
      assertTrue(
          "Modified: Reconciling did not complete in a timely fashion",
          state[0] != -1 && state[1] != -1);
      assertTrue(
          "Modified: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 2);
      assertTrue(
          "Modified: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")",
          state[1] == 3);
    } finally {
      if (editor != null && activePage != null) {
        activePage.closeEditor(editor, false);
      }
    }
  }
  @Override
  public boolean performFinish() {
    try {
      final IDocument doc =
          createDocument(typePage.getDocumentType(), typePage.getRootElementName());

      final Style style =
          VexPlugin.getDefault().getPreferences().getPreferredStyle(typePage.getDocumentType());
      if (style == null) {
        MessageDialog.openError(
            getShell(),
            Messages.getString("NewDocumentWizard.noStyles.title"),
            Messages.getString("NewDocumentWizard.noStyles.message")); // $NON-NLS-1$ //$NON-NLS-2$
        return false;
        // TODO: don't allow selection of types with no stylesheets
      }

      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      final DocumentWriter writer = new DocumentWriter();
      writer.setWhitespacePolicy(new CssWhitespacePolicy(style.getStyleSheet()));
      writer.write(doc, baos);
      baos.close();
      final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

      filePage.setInitialContents(bais);
      final IFile file = filePage.createNewFile();
      IDE.setDefaultEditor(file, VexEditor.ID);
      this.selectAndReveal(file);

      registerEditorForFilename("*." + file.getFileExtension(), VexEditor.ID); // $NON-NLS-1$

      // Open editor on new file.
      final IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
      if (dw != null) {
        final IWorkbenchPage page = dw.getActivePage();
        if (page != null) {
          IDE.openEditor(page, file, true);
        }
      }

      typePage.saveSettings();

      return true;

    } catch (final Exception ex) {
      final String message =
          MessageFormat.format(
              Messages.getString("NewDocumentWizard.errorLoading.message"),
              new Object[] {filePage.getFileName(), ex.getMessage()});
      VexPlugin.getDefault().log(IStatus.ERROR, message, ex);
      MessageDialog.openError(
          getShell(),
          Messages.getString("NewDocumentWizard.errorLoading.title"),
          "Unable to create " + filePage.getFileName()); // $NON-NLS-1$ //$NON-NLS-2$
      return false;
    }
  }
  private List<IMarkerResolution> collectResolutions(IMarker[] markers) {
    List<IMarkerResolution> resolutions = new ArrayList<>();
    for (IMarker marker : markers) {
      if (IDE.getMarkerHelpRegistry().hasResolutions(marker)) {
        IMarkerResolution[] markerResolutions = IDE.getMarkerHelpRegistry().getResolutions(marker);
        if (markerResolutions.length > 0) {
          resolutions.add(markerResolutions[0]);
        }
      }
    }

    return resolutions;
  }
 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();
 }
 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;
 }
  @Override
  public boolean performFinish() {

    IPath locationPath = new Path(page.getLocationURI().getPath());

    DartToolsPlugin.getDefault()
        .getDialogSettingsSection(NewApplicationCreationPage.NEW_APPPLICATION_SETTINGS)
        .put(
            NewApplicationCreationPage.PARENT_DIR,
            locationPath.removeLastSegments(1).toPortableString());

    if (isNestedByAnExistingProject(locationPath)) {
      createFolder(locationPath);
    } else {
      createNewProject();
    }

    if (newProject == null) {
      return false;
    }

    if (createdFile != null) {
      selectAndReveal(createdFile);

      try {
        IDE.openEditor(getWorkbench().getActiveWorkbenchWindow().getActivePage(), createdFile);
      } catch (PartInitException e) {
        DartToolsPlugin.log(e);
      }
    } else {
      selectAndReveal(newProject);
    }

    return true;
  }
  /** User clicks Finish */
  @Override
  public boolean performFinish() {
    try {
      // Create file object
      IFile file = doCreateNew(new NullProgressMonitor());
      if (file == null) {
        // that's ok, as it just didn't create a file (but maybe a folder)...
        return true;
      }

      // Scroll to file in package explorer
      BasicNewResourceWizard.selectAndReveal(file, workbench.getActiveWorkbenchWindow());

      // Open editor on new file.
      IWorkbenchWindow dw = workbench.getActiveWorkbenchWindow();
      try {
        if (dw != null) {
          IWorkbenchPage page = dw.getActivePage();
          if (page != null) {
            IEditorPart openEditor = IDE.openEditor(page, file, true);
            afterEditorCreated(openEditor);
          }
        }
      } catch (PartInitException e) {
        Log.log(e);
        return false;
      }
    } catch (Exception e) {
      Log.log(e);
      return false;
    }
    return true;
  }
 @SuppressWarnings("unchecked")
 public IEditorPart openEditor(IStructuredSelection selection) {
   Object o = selection.getFirstElement();
   EObject obj = null;
   if (o instanceof EObject) {
     obj = (EObject) o;
   }
   if (o instanceof EObjectGroup) {
     EObjectGroup group = (EObjectGroup) o;
     if (!group.getEObjects().isEmpty()) {
       obj = group.getEObjects().getFirst();
     }
   }
   if (obj != null) {
     //			URI uri = obj.eResource().getURI();
     //			String fileString = URI.decode(uri.path());
     //			fileString = fileString.replaceFirst("/resource", "");
     //			IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileString));
     //			IWorkbench workbench = PlatformUI.getWorkbench();
     IFile file = ((LinkedList<ResultModel>) viewer.getInput()).get(0).getIFile();
     IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     IWorkbenchPage page = workbenchWindow.getActivePage();
     try {
       if (file.exists()) {
         return IDE.openEditor(page, file);
       }
     } catch (PartInitException exception) {
       return null;
     }
   }
   return null;
 }
 private static void openXmlEditor(final IFileStore fileStore, int line, int column, String name) {
   assert fileStore != null;
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   if (window != null) {
     IWorkbenchPage page = window.getActivePage();
     if (page != null) {
       try {
         if (!fileStore.getName().endsWith(".pom")) { // .pom means stuff from local repository?
           IEditorPart part = IDE.openEditorOnFileStore(page, fileStore);
           reveal(selectEditorPage(part), line, column);
         } else {
           // we need special EditorInput for stuff from repository
           name = name + ".pom"; // $NON-NLS-1$
           File file = new File(fileStore.toURI());
           try {
             IEditorInput input =
                 new MavenPathStorageEditorInput(
                     name, name, file.getAbsolutePath(), readStream(new FileInputStream(file)));
             IEditorPart part = OpenPomAction.openEditor(input, name);
             reveal(selectEditorPage(part), line, column);
           } catch (IOException e) {
             log.error("failed opening editor", e);
           }
         }
       } catch (PartInitException e) {
         MessageDialog.openInformation(
             Display.getDefault().getActiveShell(), //
             Messages.PomHyperlinkDetector_error_title,
             NLS.bind(Messages.PomHyperlinkDetector_error_message, fileStore, e.toString()));
       }
     }
   }
 }
    @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;
    }
  /**
   * Given a <code>file</code> get an editor for it. If an editor has already been retrieved for the
   * given <code>file</code> then return the same already open editor.
   *
   * <p>When opening the editor it will also standardized the line endings to <code>\n</code>
   *
   * @param file open and return an editor for this
   * @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
   */
  private static StructuredTextEditor getEditor(IFile file) {
    StructuredTextEditor editor = (StructuredTextEditor) fFileToEditorMap.get(file);

    if (editor == null) {
      try {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        IEditorPart editorPart = IDE.openEditor(page, file, true, true);
        if (editorPart instanceof StructuredTextEditor) {
          editor = ((StructuredTextEditor) editorPart);
        } else {
          fail("Unable to open structured text editor");
        }

        if (editor != null) {
          standardizeLineEndings(editor);
          fFileToEditorMap.put(file, editor);
        } else {
          fail("Could not open editor for " + file);
        }
      } catch (Exception e) {
        fail("Could not open editor for " + file + " exception: " + e.getMessage());
      }
    }

    return editor;
  }
示例#15
0
 public boolean performFinish() {
   try {
     String perspId = selection.getAttribute("perspectiveId"); // $NON-NLS-1$
     IWorkbenchPage page = PDEPlugin.getActivePage();
     if (perspId != null && switchPerspective) {
       PlatformUI.getWorkbench().showPerspective(perspId, page.getWorkbenchWindow());
     }
     SampleOperation op =
         new SampleOperation(selection, namesPage.getProjectNames(), new ImportOverwriteQuery());
     getContainer().run(true, true, op);
     IFile sampleManifest = op.getSampleManifest();
     if (selectRevealEnabled) {
       selectReveal(getShell());
     }
     if (activitiesEnabled) enableActivities();
     if (sampleEditorNeeded && sampleManifest != null) IDE.openEditor(page, sampleManifest, true);
   } catch (InvocationTargetException e) {
     PDEPlugin.logException(e);
     return false;
   } catch (InterruptedException e) {
     // PDEPlugin.logException(e);
     return false;
   } catch (CoreException e) {
     PDEPlugin.logException(e);
     return false;
   } catch (OperationCanceledException e) {
     return false;
   }
   return true;
 }
示例#16
0
 private void openFile(File file, DotGraphView view) {
   if (view.currentFile == null) { // no workspace file for cur. graph
     IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path("")); // $NON-NLS-1$
     fileStore = fileStore.getChild(file.getAbsolutePath());
     if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
       IWorkbenchPage page = view.getSite().getPage();
       try {
         IDE.openEditorOnFileStore(page, fileStore);
       } catch (PartInitException e) {
         e.printStackTrace();
       }
     }
   } else {
     IWorkspace workspace = ResourcesPlugin.getWorkspace();
     IPath location = Path.fromOSString(file.getAbsolutePath());
     IFile copy = workspace.getRoot().getFileForLocation(location);
     IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
     if (registry.isSystemExternalEditorAvailable(copy.getName())) {
       try {
         view.getViewSite()
             .getPage()
             .openEditor(new FileEditorInput(copy), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
       } catch (PartInitException e) {
         e.printStackTrace();
       }
     }
   }
 }
示例#17
0
  private void openSelectedMarker() {
    ISelection sel = tableViewer.getSelection();

    if (sel instanceof IStructuredSelection) {
      Object element = ((IStructuredSelection) sel).getFirstElement();

      if (element instanceof IMarker) {
        IMarker marker = (IMarker) element;

        if (marker.getResource() instanceof IFile) {
          try {
            IDE.openEditor(getViewSite().getPage(), marker);
          } catch (PartInitException e) {
            ErrorDialog.openError(
                getSite().getShell(),
                "Error Opening Marker",
                "Unable to open an editor for the given marker: " + e.getClass().getSimpleName(),
                new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, e.toString(), e));

            DartToolsPlugin.log(e);
          }
        }
      }
    }
  }
示例#18
0
 public static void openFile(IWorkbenchPage page, IFile destinationFile, byte[] initialContent) {
   try {
     if (destinationFile != null) {
       // TODO: prompt to create the file ?  I say no, why would you try the shortcut if you didn't
       // want it created
       if (!destinationFile.exists()) {
         IPath fullPath = destinationFile.getLocation();
         if (fullPath.toFile().getParentFile().mkdirs()) {
           // create Eclipse resource so that the create file doesn't blow chunks
           destinationFile
               .getProject()
               .getFile(destinationFile.getParent().getProjectRelativePath())
               .refreshLocal(IFile.DEPTH_ZERO, null);
         }
         destinationFile.create(new ByteArrayInputStream(initialContent), false, null);
       }
       if (destinationFile.exists()) {
         IDE.openEditor(page, destinationFile);
       }
     }
   } catch (CoreException e) {
     String clazz = destinationFile.getName();
     System.err.println("OpenCakeFile can not open file: " + clazz);
     e.printStackTrace();
   }
 }
示例#19
0
  private void addActionsForSelection(IMenuManager menuManager) {
    IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();

    if (selection.size() == 1) {
      Object element = selection.getFirstElement();

      if (!(element instanceof IMarker)) {
        return;
      }

      final IMarker marker = (IMarker) element;

      IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(marker);

      for (final IMarkerResolution resolution : resolutions) {
        Action action =
            new Action(escapeSpecialChars(resolution.getLabel())) {
              @Override
              public void run() {
                resolution.run(marker);
              }
            };

        if (resolution instanceof IMarkerResolution2) {
          IMarkerResolution2 resolution2 = (IMarkerResolution2) resolution;
          Image image = resolution2.getImage();
          if (image != null) {
            action.setImageDescriptor(ImageDescriptor.createFromImage(image));
          }
        }

        menuManager.add(action);
      }
    }
  }
示例#20
0
 @Override
 public boolean close() {
   recordingSupport.setMode(RecordingMode.Stopped);
   if (isDirty()) {
     if (!openSaveDialog()) {
       return false;
     }
   }
   final boolean result = super.close();
   if (result && !parentShell.isDisposed()) {
     dbc.dispose();
     parentShell.removeShellListener(closeListener);
     parentShell.setMinimized(false);
     try {
       ShellUtilsProvider.getShellUtils().forceActive(parentShell);
     } catch (CoreException e) {
       throw new RuntimeException(e);
     }
     parentShell.setFocus();
     ITestCase model = getModel();
     if (model != null && model.exists()) {
       IFile location = (IFile) model.getResource();
       if (location != null) {
         try {
           IDE.openEditor(Q7UIPlugin.getActiveWindow().getActivePage(), location);
         } catch (PartInitException e) {
           Q7UIPlugin.log(e);
         }
       }
     }
   }
   RecordingContextManager.Instance.deactivateContext();
   return result;
 }
  protected void okPressed() {
    Object selectedElement = getSelectedElement();
    IDeveloperStudioElement resource = (IDeveloperStudioElement) selectedElement;

    /*
    if (resource.getSource() instanceof IFile) {
    	IFile selectedIFile = (IFile) resource.getSource();
    	ipathOfselection = selectedIFile.getFullPath().toString();

    	IProject project = selectedIFile.getProject();
    	RegistryFileImpl rpi = (RegistryFileImpl)selectedElement;
    	String fileName = rpi.getName();
    	String fullPath = rpi.getPath();
    	int index = fullPath.lastIndexOf('/');
    	String path = "";
    	if (index > 0) {
    		path = fullPath.substring(0,index);
    	}

    	if (path != null && !path.isEmpty())
    		try {
    			CreateNewConfigurationDialog.createRegistryResourcesForInputScemaAndOutputSchema(fileName, project, path);
    		} catch (Exception e) {
    			log.error(e.getMessage());
    		}
    }
    */

    if (showOpenResourceCheckBox && chkOpenResource.getSelection()) {
      try {
        if (resource.getSource() instanceof IFile) {
          IDE.openEditor(
              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
              (IFile) resource.getSource());
        } else if (resource.getSource() instanceof File && ((File) resource.getSource()).isFile()) {
          IFileStore fileStore =
              EFS.getLocalFileSystem().getStore(((File) resource.getSource()).toURI());
          IWorkbenchPage page =
              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
          IDE.openEditorOnFileStore(page, fileStore);
        }
      } catch (PartInitException e) {
        log.error("Error opening the resource file", e);
      }
    }
    super.okPressed();
  }
  private static boolean hasCorrections(IMarker marker) {
    if (marker == null || !marker.exists()) {
      return false;
    }

    IMarkerHelpRegistry registry = IDE.getMarkerHelpRegistry();
    return registry != null && registry.hasResolutions(marker);
  }
  public boolean openHyperLink() {
    String localiz = getLocalization();
    if (localiz == null) {
      return false;
    } else if (fBase.getUnderlyingResource() == null) {
      return false;
    } else if (fElement.length() == 0 || fElement.charAt(0) != '%') {
      return false;
    }

    IProject proj = fBase.getUnderlyingResource().getProject();
    IFile file = proj.getFile(localiz + ".properties"); // $NON-NLS-1$
    if (!file.exists()) return false;

    try {
      IEditorPart editor = IDE.openEditor(PDEPlugin.getActivePage(), file);
      if (!(editor instanceof TextEditor)) return false;
      TextEditor tEditor = (TextEditor) editor;
      IDocument doc = tEditor.getDocumentProvider().getDocument(tEditor.getEditorInput());
      if (doc == null) return false;

      try {
        String key = fElement.substring(1);
        int keyLen = key.length();
        int length = doc.getLength();
        int start = 0;
        IRegion region = null;
        FindReplaceDocumentAdapter docSearch = new FindReplaceDocumentAdapter(doc);
        while ((region = docSearch.find(start, key, true, false, false, false)) != null) {
          int offset = region.getOffset();
          if (offset > 0) {
            // check for newline before
            char c = doc.getChar(offset - 1);
            if (c != '\n' && c != '\r') {
              start += keyLen;
              continue;
            }
          }
          if (offset + keyLen < length) {
            // check for whitespace / assign symbol after
            char c = doc.getChar(offset + keyLen);
            if (!Character.isWhitespace(c) && c != '=' && c != ':') {
              start += keyLen;
              continue;
            }
          }
          tEditor.selectAndReveal(offset, keyLen);
          break;
        }
      } catch (BadLocationException e) {
        PDEPlugin.log(e);
      }

    } catch (PartInitException e) {
      return false;
    }
    return true;
  }
 @Override
 public void run() {
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   Assert.isNotNull(window);
   Shell shell = window.getShell();
   if (status.getSeverity() == IStatus.ERROR) {
     MessageDialog.openError(shell, "文件转换失败", status.getMessage());
   } else {
     // 转换完成后直接打开编辑器,不再进行弹框提示。
     // MessageDialog.openInformation(shell, "文件转换完成", status.getMessage());
     final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
     String xliffFile = conversionResult.get(Converter.ATTR_XLIFF_FILE);
     IWorkbenchPage page = window.getActivePage();
     Assert.isNotNull(page, "当前的 Active Page 为 null。无法打开转换后的文件。");
     if (xliffFile != null) {
       IEditorDescriptor editorDescriptor =
           PlatformUI.getWorkbench().getEditorRegistry().findEditor(XLIFF_EDITOR_ID);
       if (editorDescriptor != null) {
         try {
           IDE.openEditor(page, new File(xliffFile).toURI(), XLIFF_EDITOR_ID, true);
         } catch (PartInitException e) {
           MessageDialog.openInformation(
               shell, "提示", "转换完成!但是在尝试打开该 XLIFF 文件时发生异常:\n" + e.getMessage());
           e.printStackTrace();
         }
       }
     } else {
       String targetFile = conversionResult.get(Converter.ATTR_TARGET_FILE);
       if (targetFile == null) {
         MessageDialog.openError(shell, "错误", "为找到已转换文件的路径!");
       } else {
         IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
         IFile input = root.getFileForLocation(new Path(targetFile));
         try {
           // 使用外部编辑器(系统默认编辑器)打开文件。
           IDE.openEditor(page, input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
         } catch (PartInitException e) {
           MessageDialog.openInformation(
               shell, "提示", "转换完成!但是在尝试使用系统默认程序打开该文件时发生异常:\n" + e.getMessage());
           e.printStackTrace();
         }
       }
     }
   }
 }
示例#25
0
 /**
  * Open commit in editor
  *
  * @param commit
  * @param activateOnOpen <code>true</code> if the newly opened editor should be activated
  * @return opened editor part
  * @throws PartInitException
  * @since 2.1
  */
 public static final IEditorPart open(RepositoryCommit commit, boolean activateOnOpen)
     throws PartInitException {
   CommitEditorInput input = new CommitEditorInput(commit);
   return IDE.openEditor(
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
       input,
       ID,
       activateOnOpen);
 }
示例#26
0
 protected void openExtern(final IFileStore fileStore) {
   final IWorkbenchPage page = UIAccess.getActiveWorkbenchPage(true);
   try {
     IDE.openEditorOnFileStore(page, fileStore);
   } catch (final PartInitException e) {
     //			final String fileName = FileUtil.toString(fileStore);
     //			Program.launch(fileName);
   }
 }
示例#27
0
 public void open() {
   try {
     IWorkbenchPage page =
         ShipyardPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
     IDE.openEditor(page, file);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
示例#28
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;
  }
 private void openFile() {
   final IFile resource = BPELResourceAdapterFactory.getFileForObject(_implementation, _project);
   if (resource != null) {
     try {
       IDE.openEditor(getPart().getSite().getPage(), resource);
     } catch (PartInitException e) {
       Activator.getDefault().getLog().log(e.getStatus());
     }
   }
 }
 public static IEditorPart openFileInEditor(IFile input, String id) {
   if (input != null && input.exists()) {
     try {
       if (id == null) {
         IWorkbenchPage page =
             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         return IDE.openEditor(page, input, true);
       } else {
         IWorkbenchPage page =
             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         return IDE.openEditor(page, input, id, true);
       }
     } catch (PartInitException pie) {
       pie.printStackTrace();
       fail(pie.getMessage());
     }
   }
   return null;
 }