Java Code Examples for org.eclipse.ui.IEditorPart

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Archimedes, under directory /br.org.archimedes.core/src/br/org/archimedes/gui/handlers/.

Source file: CloseHandler.java

  22 
vote

public Object execute(ExecutionEvent event) throws ExecutionException {
  String all=event.getParameter(CLOSE_ALL_PARAMETER_ID);
  IWorkbenchPage activePage=HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
  if (all != null && Boolean.parseBoolean(all)) {
    activePage.closeAllEditors(true);
  }
 else {
    IEditorPart editor=HandlerUtil.getActiveEditor(event);
    activePage.closeEditor(editor,true);
  }
  return null;
}
 

Example 2

From project bioclipse.speclipse, under directory /plugins/net.bioclipse.specmol/src/net/bioclipse/specmol/actions/.

Source file: AssignAction.java

  22 
vote

@Override public void run(){
  IEditorPart activeEditor=contributor.getActiveEditorPart();
  if (activeEditor instanceof SpecMolEditor) {
    SpecMolEditor specMolEditor=(SpecMolEditor)activeEditor;
    AssignmentPage assignmentPage=specMolEditor.getSpecmoleditorpage();
    if (assignmentPage != null) {
      ArrayList<CMLPeak> peaks=assignmentPage.getAssignmentController().getSelectedPeaks();
      IAtomContainer substructure=assignmentPage.getAssignmentController().getSelectedSubstructure();
      doAssignment(substructure,peaks);
      assignmentPage.updateSpectrum(null);
      assignmentPage.setDirty(true);
    }
  }
}
 

Example 3

From project CBCJVM, under directory /eclipse/CBC/src/cbc/helpers/.

Source file: Helper.java

  22 
vote

public String getWorkspace(){
  IEditorPart activeEditor=getActiveEditor();
  String currentFile=activeEditor.getTitle();
  String fileLocation=((IPathEditorInput)activeEditor.getEditorInput()).getPath().toString();
  return fileLocation.substring(0,fileLocation.length() - (m_SrcDir.length() + 1 + currentFile.length()));
}
 

Example 4

From project ccw, under directory /ccw.debug/src/ccw/debug/.

Source file: BreakpointAdapterFactory.java

  22 
vote

public Object getAdapter(Object adaptableObject,Class adapterType){
  if (adaptableObject instanceof IEditorPart) {
    IEditorPart editorPart=(IEditorPart)adaptableObject;
    if (ClojureLineBreakpointAdapter.isCljFile(editorPart)) {
      return new ClojureLineBreakpointAdapter();
    }
  }
  return null;
}
 

Example 5

From project ceylon-ide-eclipse, under directory /plugins/com.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/code/editor/.

Source file: EditorUtility.java

  22 
vote

private static IEditorPart openInEditor(IFile file,boolean activate) throws PartInitException {
  if (file != null) {
    IWorkbenchPage p=getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (p != null) {
      IEditorPart editorPart=IDE.openEditor(p,file,activate);
      initializeHighlightRange(editorPart);
      return editorPart;
    }
  }
  return null;
}
 

Example 6

From project cilia-workbench, under directory /cilia-workbench-designer/src/fr/liglab/adele/cilia/workbench/designer/view/repositoryview/common/.

Source file: RepositoryView.java

  22 
vote

/** 
 * Opens an editor for editing a file, which name is given into parameter. Registers a listener to update the repo model as soon as the editor saves.
 * @param file the file path
 */
protected void openFileEditor(File file){
  IFileStore fileStore;
  try {
    fileStore=EFS.getLocalFileSystem().getStore(new Path(file.getAbsolutePath()));
    IWorkbenchPage page=getViewSite().getPage();
    IEditorPart editor=IDE.openEditorOnFileStore(page,fileStore);
    addEditorSavedListener(editor);
  }
 catch (  PartInitException e) {
    e.printStackTrace();
  }
}
 

Example 7

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/views/.

Source file: HeaderTableView.java

  22 
vote

@Override public void partActivated(IWorkbenchPart part){
  if (part instanceof IMetadataProvider) {
    updateFromMetaDataProvider(part);
  }
  if (part instanceof IEditorPart) {
    final IEditorPart ed=(IEditorPart)part;
    final IEditorInput in=ed.getEditorInput();
    final String path=EclipseUtils.getFilePath(in);
    if (path != null)     updatePath(path);
  }
}
 

Example 8

From project dawn-isenciaui, under directory /com.teaminabox.eclipse.wiki/src/com/teaminabox/eclipse/wiki/editors/.

Source file: WikiBrowserEditor.java

  22 
vote

public void run(){
  IWorkbenchPage[] pages=getSite().getWorkbenchWindow().getPages();
  for (  IWorkbenchPage element : pages) {
    if (((FileEditorInput)editor.getEditorInput()).getFile().getProject().equals(event.getResource())) {
      IEditorPart editorPart=element.findEditor(editor.getEditorInput());
      element.closeEditor(editorPart,true);
    }
  }
}
 

Example 9

From project dawn-tango, under directory /org.dawb.tango.extensions/src/org/dawb/tango/extensions/editors/actions/.

Source file: ConnectTangoHandler.java

  22 
vote

@Override public Object execute(ExecutionEvent event) throws ExecutionException {
  final IEditorPart part=EclipseUtils.getActiveEditor();
  if (part instanceof MultiScanMultiEditor) {
    final MultiScanMultiEditor sme=(MultiScanMultiEditor)part;
    sme.toggleConnect();
  }
  return Boolean.TRUE;
}
 

Example 10

From project dawn-ui, under directory /org.dawb.workbench.plotting/src/org/dawb/workbench/plotting/tools/profile/.

Source file: ImageTableTool.java

  22 
vote

/** 
 * Tries to get the meta from the editor part or uses the one in AbtractDataset of the image
 * @return IMetaData, may be null
 */
protected IMetaData getMetaData(){
  if (getPart() instanceof IEditorPart) {
    IEditorPart editor=(IEditorPart)getPart();
    try {
      return LoaderFactory.getMetaData(EclipseUtils.getFilePath(editor.getEditorInput()),null);
    }
 catch (    Exception e) {
      logger.error("Cannot get meta data for " + EclipseUtils.getFilePath(editor.getEditorInput()),e);
    }
  }
  return getImageTrace().getData().getMetadata();
}
 

Example 11

From project dawn-workflow, under directory /org.dawb.passerelle.actors/src/org/dawb/passerelle/editors/.

Source file: EdnaActorActions.java

  22 
vote

private static final ISubstitutionEditor getEdnaInputEditor(){
  final IEditorPart part=EclipseUtils.getActivePage().getActiveEditor();
  if (part == null)   return null;
  if (part instanceof EdnaActorMultiPageEditor) {
    final EdnaActorMultiPageEditor ed=(EdnaActorMultiPageEditor)EclipseUtils.getActivePage().getActiveEditor();
    return ed.getEdnaActorInputEditor();
  }
  if (part instanceof ISubstitutionEditor) {
    return (ISubstitutionEditor)part;
  }
  return null;
}
 

Example 12

From project droolsjbpm-tools, under directory /drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/.

Source file: ActionCompletionProcessor.java

  22 
vote

private IJavaProject getJavaProject(){
  IEditorPart editor=getEditor();
  if (editor != null && editor.getEditorInput() instanceof IFileEditorInput) {
    IFile file=((IFileEditorInput)editor.getEditorInput()).getFile();
    try {
      if (file.getProject().getNature("org.eclipse.jdt.core.javanature") != null) {
        return JavaCore.create(file.getProject());
      }
    }
 catch (    CoreException e) {
    }
  }
  return null;
}
 

Example 13

From project eclipse-instasearch, under directory /instasearch/src/it/unibz/instasearch/ui/.

Source file: InstaSearchUI.java

  22 
vote

public static String getActiveProject(){
  IEditorPart editor=getActiveEditor();
  if (editor == null)   return null;
  IAdaptable adaptable=editor.getEditorInput();
  IProject project=(IProject)adaptable.getAdapter(IProject.class);
  if (project == null) {
    IResource resource=(IResource)adaptable.getAdapter(IResource.class);
    if (resource != null)     project=resource.getProject();
  }
  if (project != null && project.isAccessible())   return project.getName();
  return null;
}
 

Example 14

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.datatools.sqltools.tablewizard.simpledb/src/com/amazonaws/eclipse/datatools/sqltools/tablewizard/simpledb/ui/popup/actions/.

Source file: AbstractEditorClosingAction.java

  21 
vote

/** 
 * Get the editor that corresponds to the table and return the reference to the editor.
 * @param table
 * @return
 */
private IEditorReference getEditor(final Table table){
  IWorkbenchWindow[] workbenchWindows=PlatformUI.getWorkbench().getWorkbenchWindows();
  for (  IWorkbenchWindow window : workbenchWindows) {
    IWorkbenchPage[] pages=window.getPages();
    for (    IWorkbenchPage page : pages) {
      IEditorReference[] editorReferences=page.getEditorReferences();
      for (      IEditorReference reference : editorReferences) {
        IEditorPart editor=reference.getEditor(false);
        if (editor instanceof TableDataEditor && table.equals(((TableDataEditor)editor).getSqlTable())) {
          return reference;
        }
      }
    }
  }
  return null;
}
 

Example 15

From project bel-editor, under directory /org.openbel.editor.ui/src/org/openbel/editor/ui/.

Source file: AstTreeViewPart.java

  21 
vote

@Override public void createPartControl(Composite parent){
  display=parent.getDisplay();
  IEditorPart part=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
  if (part instanceof ITextEditor) {
    SelectionListenerWithASTManager.getDefault().addListener((ITextEditor)part,this);
  }
  table=new Table(parent,SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
  table.setLinesVisible(true);
  table.setHeaderVisible(true);
  String[] titles={"Annotation Name","Annotation Value"};
  for (  String title : titles) {
    TableColumn column=new TableColumn(table,SWT.NONE);
    column.setText(title);
  }
  for (int i=0; i < titles.length; i++) {
    table.getColumn(i).pack();
  }
  table.setSize(table.computeSize(SWT.DEFAULT,200));
}
 

Example 16

From project bpelunit, under directory /tycho/net.bpelunit.framework.client.eclipse/src/net/bpelunit/framework/client/eclipse/launch/.

Source file: BPELLaunchMainTab.java

  21 
vote

/** 
 * Returns the current file context in the active workbench page or <code>null</code> if none.
 * @return current file in the active page or <code>null</code>
 */
protected IFile getContext(){
  IWorkbenchPage page=getActivePage();
  if (page != null) {
    ISelection selection=page.getSelection();
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection ss=(IStructuredSelection)selection;
      if (!ss.isEmpty()) {
        Object obj=ss.getFirstElement();
        if (obj instanceof IFile) {
          return (IFile)obj;
        }
      }
    }
    IEditorPart part=page.getActiveEditor();
    if (part != null) {
      IEditorInput input=part.getEditorInput();
      return (IFile)input.getAdapter(IFile.class);
    }
  }
  return null;
}
 

Example 17

From project bundlemaker, under directory /main/org.bundlemaker.core.ui/src/org/bundlemaker/core/ui/handler/.

Source file: RunTransformationScriptHandler.java

  21 
vote

@Override protected void execute(ExecutionEvent event,ISelection selection) throws Exception {
  IFile scriptFile=null;
  if (selection instanceof ITextSelection) {
    IEditorPart editor=HandlerUtil.getActiveEditor(event);
    if (editor != null) {
      IEditorInput editorInput=editor.getEditorInput();
      scriptFile=(IFile)editorInput.getAdapter(IFile.class);
    }
  }
 else {
    List<IFile> files=getSelectedObject(selection,IFile.class);
    if (files.size() > 0) {
      scriptFile=files.get(0);
    }
  }
  if (scriptFile == null) {
    return;
  }
  IBundleMakerProject bundleMakerProject=selectBundleMakerProject();
  if (bundleMakerProject == null) {
    return;
  }
  String moduleName=TransformHandler.getModuleName(scriptFile);
  TransformHandler.transform(bundleMakerProject,moduleName,scriptFile);
}
 

Example 18

From project Diver, under directory /ca.uvic.chisel.diver.sequencediagram.sc/src/ca/uvic/chisel/diver/sequencediagrams/sc/java/editors/.

Source file: ASTSequenceEditor.java

  21 
vote

@Override public void mouseDoubleClick(MouseEvent e){
  Object element=viewer.elementAt(e.x,e.y);
  int startPosition=-1;
  int length=1;
  if (element instanceof JavaMessage) {
    JavaMessage message=(JavaMessage)element;
    startPosition=message.getAST().getStartPosition();
    message.getAST().getLength();
    element=message.getSource();
  }
  if (element instanceof IAdaptable) {
    IJavaElement je=(IJavaElement)((IAdaptable)element).getAdapter(IJavaElement.class);
    if (je != null) {
      try {
        IEditorPart editor=JavaUI.openInEditor(je);
        if (startPosition >= 0) {
          if (editor instanceof ITextEditor) {
            ((ITextEditor)editor).selectAndReveal(startPosition,0);
          }
        }
      }
 catch (      PartInitException e1) {
      }
catch (      JavaModelException e1) {
      }
    }
  }
}
 

Example 19

From project dolphin, under directory /org.adarsh.jutils/src/com/tan/actions/.

Source file: EditplusAction.java

  21 
vote

public void run(){
  if (window == null)   return;
  IEditorPart editorPart=window.getActivePage().getActiveEditor();
  IEditorInput editorInput=editorPart.getEditorInput();
  IFile file=null;
  if (editorInput instanceof org.eclipse.ui.part.FileEditorInput) {
    FileEditorInput fileEditorInput=(FileEditorInput)editorInput;
    file=fileEditorInput.getFile();
  }
  Workspace workspace=(Workspace)ResourcesPlugin.getWorkspace();
  IProject project=file.getProject();
  String projectName=project.getName();
  IPath xx=project.getFullPath();
  ResourceInfo resource=workspace.getResourceInfo(xx,true,false);
  URI uri=resource.getFileStoreRoot().computeURI(xx);
  String workspacePath=uri.getPath();
  String projectPath=xx.toString();
  int idx=workspacePath.indexOf(projectPath);
  if (idx >= 0) {
    workspacePath=workspacePath.substring(0,idx);
  }
  String path=workspacePath + file.getFullPath().toOSString();
  if (path.charAt(0) == '/') {
    path=path.substring(1);
  }
  path=path.replace('/',File.separatorChar).replace('\\',File.separatorChar);
  if (isFile(path)) {
    command(" \"" + path + "\"");
  }
 else {
    path=StringUtil.replace(path,projectName + File.separatorChar,"");
    if (isFile(path)) {
      command(" \"" + path + "\"");
    }
  }
}
 

Example 20

From project Eclipse, under directory /com.mobilesorcery.sdk.html5/src/com/mobilesorcery/sdk/html5/ui/.

Source file: EvaluateHandler.java

  21 
vote

@Override public Object execute(ExecutionEvent event) throws ExecutionException {
  IEditorPart editor=HandlerUtil.getActiveEditor(event);
  IEditorInput input=editor.getEditorInput();
  IProject project=null;
  IResource resource=(IResource)input.getAdapter(IResource.class);
  if (resource != null) {
    project=resource.getProject();
  }
  ISelection selection=editor.getSite().getSelectionProvider().getSelection();
  if (project != null && selection instanceof ITextSelection) {
    ITextSelection textSelection=(ITextSelection)selection;
    final String expression=textSelection.getText();
    Thread t=new Thread(new Runnable(){
      @Override public void run(){
        IProcessConsole console=CoreMoSyncPlugin.getDefault().createConsole(MoSyncBuilder.CONSOLE_ID);
        JSODDServer server=Html5Plugin.getDefault().getReloadServer();
        Set<Integer> sessionIds=server.getSessions();
        for (        Integer sessionId : sessionIds) {
          try {
            Object result=server.evaluate(sessionId,expression,null);
            String sessionIdStr="";
            if (sessionIds.size() > 1) {
              ReloadVirtualMachine vm=server.getVM(sessionId);
              sessionIdStr="IP: " + vm.getRemoteAddr();
            }
            console.addMessage(sessionIdStr + ">" + result);
          }
 catch (          Exception e) {
          }
        }
      }
    }
);
    t.start();
  }
  return null;
}
 

Example 21

From project acceleo-modules, under directory /psm-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.psm.gen.scala.editor/src-gen/com/github/sbegaudeau/acceleo/modules/psm/gen/scala/model/scala/presentation/.

Source file: ScalaActionBarContributor.java

  19 
vote

/** 
 * When the active editor changes, this remembers the change and registers with it as a selection provider. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override public void setActiveEditor(IEditorPart part){
  super.setActiveEditor(part);
  activeEditorPart=part;
  if (selectionProvider != null) {
    selectionProvider.removeSelectionChangedListener(this);
  }
  if (part == null) {
    selectionProvider=null;
  }
 else {
    selectionProvider=part.getSite().getSelectionProvider();
    selectionProvider.addSelectionChangedListener(this);
    if (selectionProvider.getSelection() != null) {
      selectionChanged(new SelectionChangedEvent(selectionProvider,selectionProvider.getSelection()));
    }
  }
}
 

Example 22

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.webapp.editor/src-gen/org/eclipse/acceleo/tutorial/webapp/presentation/.

Source file: WebappActionBarContributor.java

  19 
vote

/** 
 * When the active editor changes, this remembers the change and registers with it as a selection provider. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override public void setActiveEditor(IEditorPart part){
  super.setActiveEditor(part);
  activeEditorPart=part;
  if (selectionProvider != null) {
    selectionProvider.removeSelectionChangedListener(this);
  }
  if (part == null) {
    selectionProvider=null;
  }
 else {
    selectionProvider=part.getSite().getSelectionProvider();
    selectionProvider.addSelectionChangedListener(this);
    if (selectionProvider.getSelection() != null) {
      selectionChanged(new SelectionChangedEvent(selectionProvider,selectionProvider.getSelection()));
    }
  }
}
 

Example 23

From project Bio-PEPA, under directory /uk.ac.ed.inf.biopepa.ui/src/uk/ac/ed/inf/biopepa/ui/actions/.

Source file: AbstractAction.java

  19 
vote

public final void setActiveEditor(IAction action,IEditorPart targetEditor){
  if (model != null)   model.removeListener(this);
  this.action=action;
  if (action == null || targetEditor == null)   return;
  bioPEPAEditor=targetEditor;
  model=((BioPEPAEditor)targetEditor).getModel();
  model.addListener(this);
  this.action=action;
  activeShell=targetEditor.getEditorSite().getShell();
  checkStatus();
}
 

Example 24

From project bndtools, under directory /bndtools.core/src/bndtools/editor/pages/.

Source file: ExportAction.java

  19 
vote

public ExportAction(Shell parentShell,IEditorPart editor,BndEditModel model){
  super("Export",SWT.RIGHT);
  this.parentShell=parentShell;
  this.editor=editor;
  this.model=model;
  configElems=Platform.getExtensionRegistry().getConfigurationElementsFor(Plugin.PLUGIN_ID,"runExportWizards");
}
 

Example 25

From project Database-Designer, under directory /plugins/org.obeonetwork.dsl.database.editor/src/org/obeonetwork/dsl/database/presentation/.

Source file: DatabaseActionBarContributor.java

  19 
vote

/** 
 * When the active editor changes, this remembers the change and registers with it as a selection provider. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override public void setActiveEditor(IEditorPart part){
  super.setActiveEditor(part);
  activeEditorPart=part;
  if (selectionProvider != null) {
    selectionProvider.removeSelectionChangedListener(this);
  }
  if (part == null) {
    selectionProvider=null;
  }
 else {
    selectionProvider=part.getSite().getSelectionProvider();
    selectionProvider.addSelectionChangedListener(this);
    if (selectionProvider.getSelection() != null) {
      selectionChanged(new SelectionChangedEvent(selectionProvider,selectionProvider.getSelection()));
    }
  }
}
 

Example 26

From project eclipse-integration-commons, under directory /org.springsource.ide.eclipse.commons.tests.util/src/org/springsource/ide/eclipse/commons/tests/util/.

Source file: StsTestUtil.java

  19 
vote

public static void saveAndWaitForEditor(final IEditorPart editor) throws CoreException {
  Display.getDefault().syncExec(new Runnable(){
    public void run(){
      editor.doSave(null);
    }
  }
);
  waitForEditor(editor);
}