Tab项目具有关闭控件

时间:2012-07-24 09:20:54

标签: eclipse-rcp

在我的eclipse插件中,在运行时我根据用户交互为Tabfolder创建多个TabItem。当创建太多TabItem时会出现问题。我正在寻找一个选项来创建一个具有关闭控件的TabItem,以便用户可以在不需要时关闭相应的TabItem。有没有办法创造这个?

2 个答案:

答案 0 :(得分:3)

如果使用CTabFolder而不是TabFolder,则可以使用CTabItem作为选项卡,并将SWT.CLOSE样式传递给构造函数。这将在选项卡上创建一个关闭按钮。

答案 1 :(得分:0)

  

SHIFT + TAB 可在编辑器之间切换   一位编辑开放。

第二次按 SHIFT + TAB 键打开 另一位编辑,但使用RCP Eclipse关闭了之前的编辑。

public class Emp_editor_open extends AbstractHandler{

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

        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
        IWorkbenchPage page = window.getActivePage();

        //Three object create in EditorInput 
        ProductEditorInput product_input=new ProductEditorInput();
        EmployeeEditorInput emp_input=new EmployeeEditorInput();
        UserEditorInput std_input = new UserEditorInput();

        IEditorReference[] editors = page.getEditorReferences();
        System.out.println("Length : "+editors.length);

        if(editors.length==0){
            //First Time or empty editors to check this condition
            try {
                page.openEditor(product_input,ProductEditor.ID);
                System.out.println("product Editor open");
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        else if(page.getActiveEditor().getTitle().equals("Product_Editor")){
            System.out.println("Product:: "+page.getActiveEditor().getTitle());
            try {
                page.closeAllEditors(true);
                page.openEditor(emp_input, EmployeeEditor.Id);
                System.out.println("Employee Editor open");
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else if(page.getActiveEditor().getTitle().equals("Employee_Editor")){
            System.out.println("Emp:: "+page.getActiveEditor().getTitle());
            try {
                page.closeAllEditors(true);
                page.openEditor(std_input, UserEditor.ID);
                System.out.println("student Editor open");
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else if(page.getActiveEditor().getTitle().equals("Student_Editor")){
            System.out.println("Product:: "+page.getActiveEditor().getTitle());
            try {
                page.closeAllEditors(true);
                page.openEditor(product_input,ProductEditor.ID);
                System.out.println("product Editor open");
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else {
            try {
                page.closeAllEditors(true);
                page.openEditor(product_input,ProductEditor.ID);
                System.out.println("product Editor open");
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }
}

的plugin.xml

    <extension point="org.eclipse.ui.commands">
        <command
                defaultHandler="rcp_demo.Toolbar.Emp_editor_open"
                id="RCP_Demo.Toolbar.emp_editor_open_cmd"
                name="Employee_Editor_open">
        </command>
    </extension>
    <extension point="org.eclipse.ui.bindings">
        <key
                commandId="RCP_Demo.Toolbar.emp_editor_open_cmd"
                schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
                sequence="M2+TAB">
        </key>              
    </extension>            

键序列:M2表示 Shift