示例#1
0
 private void handleConvert() {
   try {
     // remove listeners of Info section before we convert.  If we don't
     // we may get a model changed event while disposing the page.  Bug 156414
     fInfoSection.removeListeners();
     PDEFormEditor editor = getPDEEditor();
     IPluginModelBase model = (IPluginModelBase) editor.getAggregateModel();
     IRunnableWithProgress op = new CreateManifestOperation(model);
     IProgressService service = PlatformUI.getWorkbench().getProgressService();
     editor.doSave(null);
     service.runInUI(service, op, PDEPlugin.getWorkspace().getRoot());
     updateBuildProperties();
     editor.doSave(null);
   } catch (InvocationTargetException e) {
     MessageDialog.openError(
         PDEPlugin.getActiveWorkbenchShell(),
         PDEUIMessages.OverviewPage_error,
         e.getCause().getMessage());
     // if convert failed and this OverviewPage hasn't been removed from the editor, reattach
     // listeners
     if (!fDisposed) fInfoSection.addListeners();
   } catch (InterruptedException e) {
     // if convert failed and this OverviewPage hasn't been removed from the editor, reattach
     // listeners
     if (!fDisposed) fInfoSection.addListeners();
   }
 }
 private static IBaseModel getModelFromEditor(
     PDEFormEditor openEditor, ModelModification modification) {
   if (openEditor == null) return null;
   String name = modification.getFile().getName();
   IBaseModel model = null;
   if (name.equals(ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR)
       || name.equals(ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR)) {
     model = openEditor.getAggregateModel();
     if (model instanceof IBundlePluginModelBase)
       model = ((IBundlePluginModelBase) model).getExtensionsModel();
   } else if (name.equals(ICoreConstants.BUILD_FILENAME_DESCRIPTOR)) {
     if (openEditor instanceof BuildEditor) {
       model = openEditor.getAggregateModel();
     } else if (openEditor instanceof ManifestEditor) {
       IFormPage page = openEditor.findPage(BuildInputContext.CONTEXT_ID);
       if (page instanceof BuildSourcePage)
         model = ((BuildSourcePage) page).getInputContext().getModel();
     }
   } else if (name.equals(ICoreConstants.MANIFEST_FILENAME)) {
     model = openEditor.getAggregateModel();
     if (model instanceof IBundlePluginModelBase) return model;
   }
   if (model instanceof AbstractEditingModel) return model;
   return null;
 }
  public static IEditingModel getOpenModel(IDocument doc) {
    Iterator it = fOpenPDEEditors.values().iterator();
    while (it.hasNext()) {
      ArrayList list = (ArrayList) it.next();
      for (int i = 0; i < list.size(); i++) {
        PDEFormEditor e = (PDEFormEditor) list.get(i);
        IPluginModelBase model = (IPluginModelBase) e.getAggregateModel();
        if (model instanceof IBundlePluginModelBase) {
          IBundleModel bModel = ((IBundlePluginModelBase) model).getBundleModel();
          if (bModel instanceof IEditingModel && doc == ((IEditingModel) bModel).getDocument())
            return (IEditingModel) bModel;
          ISharedExtensionsModel eModel = ((IBundlePluginModelBase) model).getExtensionsModel();
          if (eModel instanceof IEditingModel && doc == ((IEditingModel) eModel).getDocument())
            return (IEditingModel) eModel;
        }

        //				IBuildModel bModel = model.getBuildModel();
        //				if (bModel instanceof IEditingModel &&
        //						doc == ((IEditingModel)bModel).getDocument())
        //					return (IEditingModel)bModel;

        if (model instanceof IEditingModel && doc == ((IEditingModel) model).getDocument())
          return (IEditingModel) model;
      }
    }
    return null;
  }
 private static PDEFormEditor getOpenEditor(IProject project, String editorId) {
   ArrayList list = (ArrayList) fOpenPDEEditors.get(project);
   if (list == null) return null;
   for (int i = 0; i < list.size(); i++) {
     PDEFormEditor editor = (PDEFormEditor) list.get(i);
     if (editor.getEditorSite().getId().equals(editorId)) return editor;
   }
   return null;
 }
 private static PDEFormEditor getOpenEditor(String editorID, String inputContextID, IFile file) {
   // Get the file's project
   IProject project = file.getProject();
   // Check for open editors housed in the specified project
   ArrayList list = (ArrayList) fOpenPDEEditors.get(project);
   // No open editors found
   if (list == null) {
     return null;
   }
   // Get the open editor whose
   // (1) Editor ID matches the specified editor ID
   // (2) Underlying file matches the specified file
   // Check all open editors
   for (int i = 0; i < list.size(); i++) {
     // Get the editor
     PDEFormEditor editor = (PDEFormEditor) list.get(i);
     // Check for the specified type
     // Get the editor ID
     String currentEditorID = editor.getEditorSite().getId();
     if (currentEditorID.equals(editorID) == false) {
       continue;
     }
     // Check for the specified file
     // Find the editor's input context
     InputContext context = editor.getContextManager().findContext(inputContextID);
     // Ensure we have an input context
     if (context == null) {
       continue;
     }
     // Get the editor input
     IEditorInput input = context.getInput();
     // Ensure we have a file editor input
     if ((input instanceof IFileEditorInput) == false) {
       continue;
     }
     // Get the editor's underlying file
     IFile currentFile = ((IFileEditorInput) input).getFile();
     // If the file matches the specified file, we have found the
     // specified editor
     if (currentFile.equals(file)) {
       return editor;
     }
   }
   return null;
 }
 /**
  * PDE editors should call this when they are closing down.
  *
  * @param editor the pde editor to disconnect from
  */
 public static void disconnect(PDEFormEditor editor) {
   IProject project = editor.getCommonProject();
   if (project == null) {
     // getCommonProject will return null when project is deleted with editor open - bug 226788
     // Solution is to use editor input if it is a FileEditorInput.
     IEditorInput input = editor.getEditorInput();
     if (input != null && input instanceof FileEditorInput) {
       FileEditorInput fei = (FileEditorInput) input;
       IFile file = fei.getFile();
       project = file.getProject();
     }
   }
   if (project == null) return;
   if (!fOpenPDEEditors.containsKey(project)) return;
   ArrayList list = (ArrayList) fOpenPDEEditors.get(project);
   list.remove(editor);
   if (list.size() == 0) fOpenPDEEditors.remove(project);
 }
 /**
  * PDE editors should call this during their creation.
  *
  * <p>Currently the pde editor superclass (PDEFormEditor) connects during its createPages method
  * and so this method does not need to be invoked anywhere else.
  *
  * @param editor the editor to connect to
  */
 public static void connect(PDEFormEditor editor) {
   IProject project = editor.getCommonProject();
   if (project == null) return;
   if (fOpenPDEEditors.containsKey(project)) {
     ArrayList list = (ArrayList) fOpenPDEEditors.get(project);
     if (!list.contains(editor)) list.add(editor);
   } else {
     ArrayList list = new ArrayList();
     list.add(editor);
     fOpenPDEEditors.put(project, list);
   }
 }
 protected void contextMenuAboutToShow(IMenuManager manager) {
   super.contextMenuAboutToShow(manager);
 }