2017-01-12 13 views
8

edytor istniejących lub prąd może ponownie otworzyć w tym samym oknie edytora przy użyciu rcp3 EclipseEclipse RCP: mają ten sam edytor otwarty w oknie edytora

I am tworzenie wielu edytor, który otworzyć pomyślnie, ale pewne problemy, takie jak nazwa samego edytora (aby zobaczyć mecze, redaktorzy ponownego użycia. ) mogą być wyświetlane w oknie edytora

mam jak setFocus na istniejących lub obecnego redaktora i samą nazwę edytora nie można wyświetlić w oknie edytora.

Nazwa pakietu: rcp_demo.Editor

nazwa klasy: UserCommand.java, UserEditor.java i UserEditorInput.java

nazwa klasy: EmpCommand.java, EmployeeEditor.java i EmployeeEditorInput. java

package rcp_demo.Editor; 

import org.eclipse.core.commands.AbstractHandler; 
import org.eclipse.core.commands.ExecutionEvent; 
import org.eclipse.core.commands.ExecutionException; 
import org.eclipse.ui.IWorkbenchPage; 
import org.eclipse.ui.IWorkbenchWindow; 
import org.eclipse.ui.PartInitException; 
import org.eclipse.ui.handlers.HandlerUtil; 

public class UserCommand extends AbstractHandler{ 

    public static final String ID = "rcp_demo.Editor.UserCommand"; 

    @Override 
    public Object execute(ExecutionEvent event) throws ExecutionException { 

     IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); 
      IWorkbenchPage page = window.getActivePage(); 
      UserEditorInput input = new UserEditorInput(); 
      try { 
       if(page.getActivePart().getTitle().toString().equals("Student_Editor")) 
       { 
        page.findEditor(input); 
        System.out.println("Student Editor exist.........."); 
       } 
       else 
       { 
        page.openEditor(input, UserEditor.ID); 
        System.out.println("Student Editor open"); 
       } 
      } catch (PartInitException e) { 
       System.out.println("Error:" + this.getClass().getName() + ":" + e); 
       e.printStackTrace(); 
       throw new ExecutionException("Error open UserEditor"); 
      } 
     return null; 
    } 
} 

plugin.xml

lista Editor

<extension 
     point="org.eclipse.ui.editors"> 
     <editor 
      class="rcp_demo.Editor.UserEditor" 
      default="false" 
      id="rcp_demo.Editor.user" 
      name="Student_Editor"> 
     </editor> 
     <editor 
      class="rcp_demo.Editor.EmployeeEditor" 
      default="false" 
      id="rcp_demo.Editor.emp" 
      name="Employee_Editor"> 
     </editor> 
    </extension> 

lista poleceń

<extension 
     point="org.eclipse.ui.commands"> 
     <command 
      defaultHandler="rcp_demo.Editor.UserCommand" 
      id="rcp_demo.Editor.UserCommand" 
      name="Call UserEditor"> 
     </command> 
     <command 
      defaultHandler="rcp_demo.Editor.EmpCommand" 
      id="rcp_demo.Editor.EmpCommand" 
      name="call EmpEditor"> 
     </command> 
    </extension> 

Przed wyjście


Student Editor otwarty

Editor urzędnik otwarty

Student Editor otwarty

Editor urzędnik otwarty


(Po) Moja Wymagane wyjście


Student Editor otwarty

Editor urzędnik otwarty

Student Editor istnieć ..........

Pracownik Editor istnieć .........

Edytor uczniów istnieje ..........

Edytor pracowników istnieje .........


gotowy otwarty edytor może nie raz drugi otwarty ...

+0

Niestety, ale nie rozumiem, o co prosicie. –

+0

dzięki za powtórzenie ... pełne opisać to pytanie .. –

+0

Przepraszam, ale nadal nie rozumiem dokładnie, na czym polega problem. Dlaczego sprawdzasz tytuł części, jeśli chcesz otworzyć inny edytor? –

Odpowiedz

2

mam rozwiązać to pytanie

nazwę

pakiet: rcp_demo.Editor

nazwa klasy: EmpCommand.java, EmployeeEditor.ja va i EmployeeEditorInput.java

package rcp_demo.Editor; 

import org.eclipse.core.commands.AbstractHandler; 
import org.eclipse.core.commands.ExecutionEvent; 
import org.eclipse.core.commands.ExecutionException; 
import org.eclipse.ui.IEditorReference; 
import org.eclipse.ui.IWorkbenchPage; 
import org.eclipse.ui.IWorkbenchWindow; 
import org.eclipse.ui.PartInitException; 
import org.eclipse.ui.handlers.HandlerUtil; 

public class EmpCommand extends AbstractHandler { 
    public static final String Id = "rcp_demo.Editor.EmpCommand"; 

    @Override 
    public Object execute(ExecutionEvent event) throws ExecutionException { 

     IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); 
      IWorkbenchPage page = window.getActivePage(); 
      IEditorReference[] editors = page.getEditorReferences(); 
      EmployeeEditorInput input = new EmployeeEditorInput(); 

      //All Comments are easily understand 
      //public class EmployeeEditorInput implements IEditorInput{} 

      for (int i=0; i<editors.length; i++) { 

      //List out all Exist editor 
      //compare with EmployeeEditor.Id="rcp_demo.Editor.emp"; 

       if (editors[i].getId().equals(EmployeeEditor.Id)) { 

       //public class EmployeeEditor extends EditorPart 
       //{ 
       // public static final String Id="rcp_demo.Editor.emp"; 
       //  public void createPartControl(Composite parent) {.....} 
       //} 

        page.activate(editors[i].getEditor(true)); 
        System.out.println("set focus an existing editor(Employee)"); 
        return null; 
       } 
      } 
      try { 

       //open new Editor like EmployeeEditor.Id="rcp_demo.Editor.emp"; 
       page.openEditor(input,EmployeeEditor.Id); 
       System.out.println("open Editor(Employee) "); 
      } catch (PartInitException e) { 
       e.printStackTrace(); 
      } 
     return null; 
    } 
} 
Powiązane problemy