Example #1
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();
       }
     }
   }
 }
  /*
   * @see org.eclipse.swt.dnd.DragSourceListener#dragStart
   */
  @Override
  public void dragStart(DragSourceEvent event) {
    fEditorInputDatas = new ArrayList<EditorInputData>();

    ISelection selection = fProvider.getSelection();
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      for (Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) {
        Object element = iter.next();
        IEditorInput editorInput = EditorUtility.getEditorInput(element);
        if (editorInput != null && editorInput.getPersistable() != null) {
          try {
            String editorId = EditorUtility.getEditorID(editorInput);
            // see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..):
            IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
            IEditorDescriptor editorDesc = editorReg.findEditor(editorId);
            if (editorDesc != null && !editorDesc.isOpenExternal()) {
              fEditorInputDatas.add(
                  EditorInputTransfer.createEditorInputData(editorId, editorInput));
            }
          } catch (PartInitException e) {
            JavaPlugin.log(e);
          }
        }
      }
    }

    event.doit = fEditorInputDatas.size() > 0;
  }
Example #3
0
  /** Restores the object state from the memento. */
  public IStatus restoreState() {
    Assert.isTrue(!isRestored());

    IStatus result = Status.OK_STATUS;
    IMemento memento = this.memento;
    this.memento = null;

    String factoryId = memento.getString(IWorkbenchConstants.TAG_FACTORY_ID);
    if (factoryId == null) {
      WorkbenchPlugin.log("Unable to restore mru list - no input factory ID."); // $NON-NLS-1$
      return result;
    }
    IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryId);
    if (factory == null) {
      return result;
    }
    IMemento persistableMemento = memento.getChild(IWorkbenchConstants.TAG_PERSISTABLE);
    if (persistableMemento == null) {
      WorkbenchPlugin.log(
          "Unable to restore mru list - no input element state: " + factoryId); // $NON-NLS-1$
      return result;
    }
    IAdaptable adaptable = factory.createElement(persistableMemento);
    if (adaptable == null || (adaptable instanceof IEditorInput) == false) {
      return result;
    }
    input = (IEditorInput) adaptable;
    // Get the editor descriptor.
    String editorId = memento.getString(IWorkbenchConstants.TAG_ID);
    if (editorId != null) {
      IEditorRegistry registry = WorkbenchPlugin.getDefault().getEditorRegistry();
      descriptor = registry.findEditor(editorId);
    }
    return result;
  }
Example #4
0
  public static IEditorDescriptor getEditorDescription(IFile file) {
    IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();

    IEditorDescriptor selectedDescriptor = null;

    String defaultEditorID = null;
    try {
      defaultEditorID = file.getPersistentProperty(IDE.EDITOR_KEY);
    } catch (CoreException e) {
    }
    if (defaultEditorID != null) selectedDescriptor = editorReg.findEditor(defaultEditorID);

    if (selectedDescriptor == null) {

      /*
      JastAddModel model = JastAddModelProvider.getModel(file);
      if (model != null) {
      */
      IEditorDescriptor[] descriptors = editorReg.getEditors(file.getName());
      for (IEditorDescriptor descriptor : descriptors)
        if (descriptor.getId().equals(JastAddJEditor.EDITOR_ID)) selectedDescriptor = descriptor;
      if (selectedDescriptor == null && descriptors.length > 0) selectedDescriptor = descriptors[0];
      // }
    }
    return selectedDescriptor;
  }
 /**
  * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.IEditorInput,
  *     java.lang.Object)
  */
 public String getEditorId(IEditorInput input, Object element) {
   if (input instanceof DisassemblyEditorInput) return "org.eclipse.ui.DefaultTextEditor";
   IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
   IEditorDescriptor descriptor = registry.getDefaultEditor(input.getName());
   if (descriptor != null) {
     return descriptor.getId();
   } else {
     return "org.eclipse.ui.DefaultTextEditor";
   }
 }
 @Override
 IWorkbenchPart createErrorPart() {
   IStatus status =
       new Status(
           IStatus.ERROR,
           WorkbenchPlugin.PI_WORKBENCH,
           NLS.bind(WorkbenchMessages.EditorManager_missing_editor_descriptor, descriptorId));
   IEditorRegistry registry = getPage().getWorkbenchWindow().getWorkbench().getEditorRegistry();
   descriptor = (EditorDescriptor) registry.findEditor(EditorRegistry.EMPTY_EDITOR_ID);
   return createErrorPart(status);
 }
Example #7
0
  /** This method is called upon plug-in activation */
  @Override
  public void start(final BundleContext context) throws Exception {
    super.start(context);

    // also provide someps extra functionality to the right-click editor
    RightClickSupport.addRightClickGenerator(new GenerateTrack());
    RightClickSupport.addRightClickGenerator(new GroupTracks());
    RightClickSupport.addRightClickGenerator(new GenerateInfillSegment());
    RightClickSupport.addRightClickGenerator(new MergeTracks());
    RightClickSupport.addRightClickGenerator(new MergeContacts());
    RightClickSupport.addRightClickGenerator(new GenerateTMASegment());
    RightClickSupport.addRightClickGenerator(new GenerateTUASolution());
    RightClickSupport.addRightClickGenerator(new GenerateTrackFromActiveCuts());
    RightClickSupport.addRightClickGenerator(new GenerateSensorRangePlot());
    RightClickSupport.addRightClickGenerator(new GenerateNewSensor());
    RightClickSupport.addRightClickGenerator(new GenerateNewSensorContact());
    RightClickSupport.addRightClickGenerator(new GenerateNewNarrativeEntry());
    RightClickSupport.addRightClickGenerator(new ImportAsTrack());
    RightClickSupport.addRightClickGenerator(new TrimTrack());
    RightClickSupport.addRightClickGenerator(new RainbowShadeSonarCuts());
    RightClickSupport.addRightClickGenerator(new InterpolateTrack());

    // and the Replay importer/exporter (used to export items from the
    // layer-manager)
    ImportManager.addImporter(new Debrief.ReaderWriter.Replay.ImportReplay());

    // make Debrief the default editor for XML files
    final IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
    editorRegistry.setDefaultEditor("*.xml", "org.mwc.debrief.PlotEditor");

    // tell the message provider where it can fire messages to
    MessageProvider.Base.setProvider(this);

    _myImageHelper = new DebriefImageHelper();

    // give the LayerManager our image creator.
    CoreViewLabelProvider.addImageHelper(_myImageHelper);

    // provide helper for triggering 'new-leg' operation
    final GiveMeALeg triggerNewLeg =
        new GiveMeALeg() {

          @Override
          public void createLegFor(final Layer parent) {
            final InsertTrackSegment ts = new InsertTrackSegment(parent);
            ts.run(null);
          }
        };

    CompositeTrackWrapper.setNewLegHelper(triggerNewLeg);
    CompositeTrackWrapper.initialise(CorePlugin.getToolParent());
    AISDecoder.initialise(CorePlugin.getToolParent());
  }
Example #8
0
 /** Returns the image descriptor for the given editor descriptor, or null if it has no image. */
 private ImageDescriptor getImageDescriptor(IEditorDescriptor editorDesc) {
   ImageDescriptor imageDesc = null;
   if (editorDesc == null) {
     imageDesc = registry.getImageDescriptor(getFileRevision().getName());
     // TODO: is this case valid, and if so, what are the implications
     // for content-type editor bindings?
   } else {
     imageDesc = editorDesc.getImageDescriptor();
   }
   if (imageDesc == null) {
     if (editorDesc.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID)) {
       imageDesc = registry.getSystemExternalEditorImageDescriptor(getFileRevision().getName());
     }
   }
   return imageDesc;
 }
  @Override
  public IEditorDescriptor getEditorDescriptor(String name, IEditorRegistry editorReg) {
    IEditorDescriptor editorDesc = null;
    // next check the OS for in-place editor (OLE on Win32)
    if (editorReg.isSystemInPlaceEditorAvailable(name)) {
      editorDesc = editorReg.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
    }

    // next check with the OS for an external editor
    if (editorDesc == null && editorReg.isSystemExternalEditorAvailable(name)) {
      editorDesc = editorReg.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
    }

    // next lookup the default text editor
    if (editorDesc == null) {
      editorDesc = editorReg.findEditor(IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
    }
    return editorDesc;
  }
  /**
   * 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();
    }
  }
  public EditorReference(
      IEclipseContext windowContext,
      IWorkbenchPage page,
      MPart part,
      IEditorInput input,
      EditorDescriptor descriptor,
      IMemento editorState) {
    super(windowContext, page, part);
    this.input = input;
    this.descriptor = descriptor;
    this.editorState = editorState;

    if (descriptor == null) {
      try {
        String memento = getModel().getPersistedState().get(MEMENTO_KEY);
        if (memento == null) {
          descriptorId = EditorRegistry.EMPTY_EDITOR_ID;
        } else {
          XMLMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(memento));
          IEditorRegistry registry =
              getPage().getWorkbenchWindow().getWorkbench().getEditorRegistry();
          descriptorId = createReadRoot.getString(IWorkbenchConstants.TAG_ID);
          this.descriptor = (EditorDescriptor) registry.findEditor(descriptorId);

          boolean pinnedVal =
              "true"
                  .equals(createReadRoot.getString(IWorkbenchConstants.TAG_PINNED)); // $NON-NLS-1$
          setPinned(pinnedVal);

          String ttip = createReadRoot.getString(IWorkbenchConstants.TAG_TOOLTIP);
          part.getTransientData().put(IPresentationEngine.OVERRIDE_TITLE_TOOL_TIP_KEY, ttip);
        }
      } catch (WorkbenchException e) {
        WorkbenchPlugin.log(e);
      }
    } else {
      descriptorId = this.descriptor.getId();
    }
  }
Example #12
0
  private void initializeTitle(IEditorInput input) {

    Image oldImage = fTitleImage;
    fTitleImage = null;
    String title = ""; // $NON-NLS-1$

    if (input != null) {
      IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
      IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
      ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;

      fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
      title = input.getName();
    }

    setTitleImage(fTitleImage);
    setPartName(title);

    firePropertyChange(PROP_DIRTY);

    if (oldImage != null && !oldImage.isDisposed()) oldImage.dispose();
  }
  public EditorReference(
      IEclipseContext windowContext,
      IWorkbenchPage page,
      MPart part,
      IEditorInput input,
      EditorDescriptor descriptor,
      IMemento editorState) {
    super(windowContext, page, part);
    this.input = input;
    this.descriptor = descriptor;
    this.editorState = editorState;

    if (descriptor == null) {
      try {
        String memento = getModel().getPersistedState().get(MEMENTO_KEY);
        if (memento == null) {
          descriptorId = EditorRegistry.EMPTY_EDITOR_ID;
        } else {
          XMLMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(memento));
          IEditorRegistry registry =
              getPage().getWorkbenchWindow().getWorkbench().getEditorRegistry();
          descriptorId = createReadRoot.getString(IWorkbenchConstants.TAG_ID);
          this.descriptor = (EditorDescriptor) registry.findEditor(descriptorId);
        }

        if (this.descriptor == null) {
          setImageDescriptor(ImageDescriptor.getMissingImageDescriptor());
        } else {
          setImageDescriptor(this.descriptor.getImageDescriptor());
        }
      } catch (WorkbenchException e) {
        WorkbenchPlugin.log(e);
      }
    } else {
      descriptorId = this.descriptor.getId();
      setImageDescriptor(this.descriptor.getImageDescriptor());
    }
  }
 @Override
 public void dispose() {
   EDITOR_REGISTRY.removePropertyListener(editorRegistryListener);
   super.dispose();
 }
 public void init(ICommonContentExtensionSite config) {
   this.config = config;
   EDITOR_REGISTRY.addPropertyListener(editorRegistryListener);
 }
Example #16
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 Image createWorkbenchImage(String type) {
   IEditorRegistry er = getDefault().getWorkbench().getEditorRegistry();
   ImageDescriptor id = er.getImageDescriptor("foo." + type); // $NON-NLS-1$
   return id.createImage();
 }