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;
 }
 /**
  * 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 static void setOrdered(IdMap idmap, ArrayList idmapOrdered) {
   ArrayList Ordered = new ArrayList();
   for (Iterator iter_ordered = idmapOrdered.iterator(); iter_ordered.hasNext(); ) {
     Mapping mapping = new Mapping();
     String signature = (String) iter_ordered.next();
     int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR, signature.length() - 2);
     if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1)
       mapping.setSignature(""); // $NON-NLS-1$
     else
       mapping.setSignature(
           signature.substring(XMLStructureCreator.ROOT_ID.length() + 1, end_of_signature));
     mapping.setElement(signature.substring(end_of_signature + 1, signature.length() - 1));
     Ordered.add(mapping);
   }
   idmap.setOrdered(Ordered);
 }
 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);
 }
 private void editOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     String idmapALKey = mapping.getKey();
     idmapAL.remove(idmapALKey);
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, null, true);
     if (dialog.open() == Window.OK) {
       idmapALKey = mapping.getKey();
       idmapAL.add(idmapALKey);
       fOrderedTable.remove(fOrderedTable.indexOf(itemsOrdered[0]));
       newOrderedTableItem(mapping, true);
     }
   }
 }
 protected void selectionChanged() {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     // Refresh Mappings Table
     fMappingsTable.removeAll();
     Vector Mappings = ((IdMap) items[0].getData()).getMappings();
     for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
       newMappingsTableItem((Mapping) enumeration.nextElement(), false);
     }
     // Refresh Ordered Table
     fOrderedTable.removeAll();
     ArrayList Ordered = ((IdMap) items[0].getData()).getOrdered();
     if (Ordered != null) {
       for (Iterator iter_ordered = Ordered.iterator(); iter_ordered.hasNext(); ) {
         newOrderedTableItem((Mapping) iter_ordered.next(), false);
       }
     }
   }
   updateEnabledState();
 }
예제 #9
0
  private ArrayList convertPkgList(ArrayList pkgList) {
    ArrayList conList = new ArrayList();
    Iterator it = pkgList.iterator();
    while (it.hasNext()) {
      CallData cd = (CallData) it.next();
      TestNode tn = null;
      if (alreadyDone.containsKey(cd)) {
        tn = (TestNode) alreadyDone.get(cd);
      } else {
        tn = new TestNode();
        tn.setData(cd.getData());
        alreadyDone.put(cd, tn);
        if (cd.getChildren().size() != 0) {
          tn.setChildren(convertPkgList(cd.getChildren()));
        }
        if (cd.getOutputs().size() != 0) {
          tn.setOutputs(convertPkgList(cd.getOutputs()));
        }
      }
      conList.add(tn);
    }

    return conList;
  }
 private void handleAddWorkingSet() {
   IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
   IWorkingSetSelectionDialog dialog =
       manager.createWorkingSetSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), true);
   if (dialog.open() == Window.OK) {
     IWorkingSet[] workingSets = dialog.getSelection();
     IProduct product = getProduct();
     IProductModelFactory factory = product.getModel().getFactory();
     ArrayList<IProductPlugin> pluginList = new ArrayList<IProductPlugin>();
     for (int i = 0; i < workingSets.length; i++) {
       IAdaptable[] elements = workingSets[i].getElements();
       for (int j = 0; j < elements.length; j++) {
         IPluginModelBase model = findModel(elements[j]);
         if (model != null) {
           IProductPlugin plugin = factory.createPlugin();
           IPluginBase base = model.getPluginBase();
           plugin.setId(base.getId());
           pluginList.add(plugin);
         }
       }
     }
     product.addPlugins(pluginList.toArray(new IProductPlugin[pluginList.size()]));
   }
 }
  public static void handleAddRequired(IProductPlugin[] plugins, boolean includeOptional) {
    if (plugins.length == 0) return;

    ArrayList<BundleDescription> list = new ArrayList<BundleDescription>(plugins.length);
    for (int i = 0; i < plugins.length; i++) {
      list.add(TargetPlatformHelper.getState().getBundle(plugins[i].getId(), null));
    }
    DependencyCalculator calculator = new DependencyCalculator(includeOptional);
    calculator.findDependencies(list.toArray());

    BundleDescription[] bundles = TargetPlatformHelper.getState().getBundles();
    for (int i = 0; i < bundles.length; i++) {
      HostSpecification host = bundles[i].getHost();
      if (host != null
          && !("org.eclipse.ui.workbench.compatibility"
              .equals(bundles[i].getSymbolicName())) // $NON-NLS-1$
          && calculator.containsPluginId(host.getName())) {
        calculator.findDependency(bundles[i]);
      }
    }

    Collection<?> dependencies = calculator.getBundleIDs();

    IProduct product = plugins[0].getProduct();
    IProductModelFactory factory = product.getModel().getFactory();
    IProductPlugin[] requiredPlugins = new IProductPlugin[dependencies.size()];
    int i = 0;
    Iterator<?> iter = dependencies.iterator();
    while (iter.hasNext()) {
      String id = iter.next().toString();
      IProductPlugin plugin = factory.createPlugin();
      plugin.setId(id);
      requiredPlugins[i++] = plugin;
    }
    product.addPlugins(requiredPlugins);
  }
 private void removeOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0 && itemsIdMaps.length > 0) {
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     idmapAL.remove(mapping.getKey());
     if (idmapAL.size() <= 0) fOrderedElements.remove(idmap.getName());
     ArrayList ordered = idmap.getOrdered();
     ordered.remove(mapping);
     if (ordered.size() <= 0) idmap.setOrdered(null);
     itemsOrdered[0].dispose(); // Table is single selection
   }
 }
  private void editIdMap(Shell shell) {
    TableItem[] items = fIdMapsTable.getSelection();
    if (items.length > 0) {
      IdMap idmap = (IdMap) items[0].getData();
      XMLCompareEditCopyIdMapDialog dialog =
          new XMLCompareEditCopyIdMapDialog(shell, idmap, fIdMaps, fIdMapsInternal);
      if (dialog.open() == Window.OK) {
        String new_idmapName = dialog.getResult();
        if (!fIdMaps.containsKey(new_idmapName)) {
          // copy over id mappings
          Vector newMappings = new Vector();
          IdMap newIdMap = new IdMap(new_idmapName, false, newMappings);
          HashMap newIdmapHM = new HashMap();
          fIdMaps.put(newIdMap.getName(), newIdmapHM);
          Vector Mappings = idmap.getMappings();
          for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
            Mapping mapping = (Mapping) enumeration.nextElement();
            Mapping newMapping =
                new Mapping(mapping.getElement(), mapping.getSignature(), mapping.getIdAttribute());
            newMappings.add(newMapping);
            newIdmapHM.put(newMapping.getKey(), newMapping.getIdAttribute());
          }
          // copy over ordered entries
          ArrayList orderedAL = idmap.getOrdered();
          if (orderedAL != null && orderedAL.size() > 0) {
            ArrayList newOrderedAL = new ArrayList();
            newIdMap.setOrdered(newOrderedAL);
            ArrayList idmapOrdered = new ArrayList();
            fOrderedElements.put(newIdMap.getName(), idmapOrdered);
            for (Iterator iter = orderedAL.iterator(); iter.hasNext(); ) {
              Mapping ordered = (Mapping) iter.next();
              Mapping newOrdered = new Mapping(ordered.getElement(), ordered.getSignature());
              newOrderedAL.add(newOrdered);
              idmapOrdered.add(newOrdered.getKey());
            }
          }

          newIdMapsTableItem(newIdMap, true);
          selectionChanged();
        }
      }
    }
  }
 private void addOrdered(Shell shell) {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     //			Set orderedSet= fOrderedElements.keySet();
     //			for (Iterator iter= orderedSet.iterator(); iter.hasNext(); ) {
     //				String IdMapName= (String) iter.next();
     //				ArrayList ordered= (ArrayList) fOrderedElements.get(IdMapName);
     //				for (Iterator iter2= ordered.iterator(); iter2.hasNext(); ) {
     //					System.out.println(IdMapName + ": " + iter2.next()); //$NON-NLS-1$
     //				}
     //			}
     IdMap idmap = (IdMap) items[0].getData();
     Mapping mapping = new Mapping();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     if (idmapAL == null) idmapAL = new ArrayList();
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, idmapAL, false);
     if (dialog.open() == Window.OK) {
       String idmapALKey = mapping.getKey();
       if (!idmapAL.contains(idmapALKey)) {
         idmapAL.add(idmapALKey);
         newOrderedTableItem(mapping, true);
         ArrayList ordered = idmap.getOrdered();
         if (ordered == null) {
           ordered = new ArrayList();
           ordered.add(mapping);
           idmap.setOrdered(ordered);
         } else {
           ordered.add(mapping);
         }
         if (!fOrderedElements.containsKey(idmap.getName()))
           fOrderedElements.put(idmap.getName(), idmapAL);
       }
     }
   }
 }
예제 #15
0
  public void fill(Menu menu, int index) {
    final IFileRevision fileRevision = getFileRevision();
    if (fileRevision == null) {
      return;
    }

    IEditorDescriptor defaultTextEditor =
        registry.findEditor("org.eclipse.ui.DefaultTextEditor"); // $NON-NLS-1$
    IEditorDescriptor preferredEditor = Utils.getDefaultEditor(fileRevision);

    Object[] editors = Utils.getEditors(fileRevision);
    Collections.sort(Arrays.asList(editors), comparer);
    boolean defaultFound = false;

    // Check that we don't add it twice. This is possible
    // if the same editor goes to two mappings.
    ArrayList alreadyMapped = new ArrayList();

    for (int i = 0; i < editors.length; i++) {
      IEditorDescriptor editor = (IEditorDescriptor) editors[i];
      if (!alreadyMapped.contains(editor)) {
        createMenuItem(menu, editor, preferredEditor);
        if (defaultTextEditor != null && editor.getId().equals(defaultTextEditor.getId())) {
          defaultFound = true;
        }
        alreadyMapped.add(editor);
      }
    }

    // Only add a separator if there is something to separate
    if (editors.length > 0) {
      new MenuItem(menu, SWT.SEPARATOR);
    }

    // Add default editor. Check it if it is saved as the preference.
    if (!defaultFound && defaultTextEditor != null) {
      createMenuItem(menu, defaultTextEditor, preferredEditor);
    }

    // TODO : We might perhaps enable inplace and system external editors menu items
    /*// Add system editor
    IEditorDescriptor descriptor = registry
    		.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
    final MenuItem systemEditorMenuItem = createMenuItem(menu, descriptor,
    		preferredEditor);
    systemEditorMenuItem.setEnabled(false);

    // Add system in-place editor
    descriptor = registry
    		.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);

    final MenuItem inPlaceEditorMenuItem = (descriptor != null) ? createMenuItem(
    		menu, descriptor, preferredEditor)
    		: null;
    if (inPlaceEditorMenuItem != null)
    	inPlaceEditorMenuItem.setEnabled(false);

    Job job = new Job("updateOpenWithMenu") { //$NON-NLS-1$
    	protected IStatus run(IProgressMonitor monitor) {
    		try {
    			final boolean isFile = fileRevision.getStorage(monitor) instanceof IFile;
    			Display.getDefault().asyncExec(new Runnable() {
    				public void run() {
    					if (inPlaceEditorMenuItem != null
    							&& !inPlaceEditorMenuItem.isDisposed())
    						inPlaceEditorMenuItem.setEnabled(isFile);
    					if (!systemEditorMenuItem.isDisposed())
    						systemEditorMenuItem.setEnabled(isFile);
    				}
    			});
    			return Status.OK_STATUS;
    		} catch (CoreException e) {
    			return new Status(IStatus.WARNING, TeamUIPlugin.ID, null, e);
    		}
    	};
    };
    job.setSystem(true);
    job.schedule();*/

    createDefaultMenuItem(menu, fileRevision);

    // add Other... menu item
    createOtherMenuItem(menu);
  }
  private static TextFileChange[] generateModelEdits(
      final ModelModification modification, final IProgressMonitor monitor, boolean performEdits) {
    ArrayList edits = new ArrayList();
    // create own model, attach listeners and grab text edits
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    IFile[] files;
    if (modification.isFullBundleModification()) {
      files = new IFile[2];
      files[F_Bi] = modification.getManifestFile();
      files[F_Xi] = modification.getXMLFile();
    } else {
      files = new IFile[] {modification.getFile()};
    }
    // need to monitor number of successful buffer connections for disconnection purposes
    // @see } finally { statement
    int sc = 0;
    try {
      ITextFileBuffer[] buffers = new ITextFileBuffer[files.length];
      IDocument[] documents = new IDocument[files.length];
      for (int i = 0; i < files.length; i++) {
        if (files[i] == null || !files[i].exists()) continue;
        manager.connect(files[i].getFullPath(), LocationKind.NORMALIZE, monitor);
        sc++;
        buffers[i] = manager.getTextFileBuffer(files[i].getFullPath(), LocationKind.NORMALIZE);
        if (performEdits && buffers[i].isDirty()) buffers[i].commit(monitor, true);
        documents[i] = buffers[i].getDocument();
      }

      IBaseModel editModel;
      if (modification.isFullBundleModification())
        editModel = prepareBundlePluginModel(files, documents, !performEdits);
      else editModel = prepareAbstractEditingModel(files[0], documents[0], !performEdits);

      modification.modifyModel(editModel, monitor);

      IModelTextChangeListener[] listeners = gatherListeners(editModel);
      for (int i = 0; i < listeners.length; i++) {
        if (listeners[i] == null) continue;
        TextEdit[] currentEdits = listeners[i].getTextOperations();
        if (currentEdits.length > 0) {
          MultiTextEdit multi = new MultiTextEdit();
          multi.addChildren(currentEdits);
          if (performEdits) {
            multi.apply(documents[i]);
            buffers[i].commit(monitor, true);
          }
          TextFileChange change = new TextFileChange(files[i].getName(), files[i]);
          change.setEdit(multi);
          // If the edits were performed right away (performEdits == true) then
          // all the names are null and we don't need the granular detail anyway.
          if (!performEdits) {
            for (int j = 0; j < currentEdits.length; j++) {
              String name = listeners[i].getReadableName(currentEdits[j]);
              if (name != null) change.addTextEditGroup(new TextEditGroup(name, currentEdits[j]));
            }
          }
          // save the file after the change applied
          change.setSaveMode(TextFileChange.FORCE_SAVE);
          setChangeTextType(change, files[i]);
          edits.add(change);
        }
      }
    } catch (CoreException e) {
      PDEPlugin.log(e);
    } catch (MalformedTreeException e) {
      PDEPlugin.log(e);
    } catch (BadLocationException e) {
      PDEPlugin.log(e);
    } finally {
      // don't want to over-disconnect in case we ran into an exception during connections
      // dc <= sc stops this from happening
      int dc = 0;
      for (int i = 0; i < files.length && dc <= sc; i++) {
        if (files[i] == null || !files[i].exists()) continue;
        try {
          manager.disconnect(files[i].getFullPath(), LocationKind.NORMALIZE, monitor);
          dc++;
        } catch (CoreException e) {
          PDEPlugin.log(e);
        }
      }
    }
    return (TextFileChange[]) edits.toArray(new TextFileChange[edits.size()]);
  }