Search in sources :

Example 1 with SwtDeck

use of org.pentaho.ui.xul.swt.tags.SwtDeck in project pentaho-kettle by pentaho.

the class SpoonPerspectiveManager method initialize.

public void initialize() {
    XulToolbar mainToolbar = (XulToolbar) domContainer.getDocumentRoot().getElementById("main-toolbar");
    SwtDeck deck = (SwtDeck) domContainer.getDocumentRoot().getElementById("canvas-deck");
    int y = 0;
    int perspectiveIdx = 0;
    Class<? extends SpoonPerspective> perClass = null;
    List<SpoonPerspective> perspectives = getPerspectives();
    if (this.startupPerspective != null) {
        for (int i = 0; i < perspectives.size(); i++) {
            if (perspectives.get(i).getId().equals(this.startupPerspective)) {
                perspectiveIdx = i;
                break;
            }
        }
    }
    final List<PerspectiveData> perspectiveList = new ArrayList<>();
    final ToolBar swtToolbar = (ToolBar) mainToolbar.getManagedObject();
    final Shell shell = swtToolbar.getShell();
    final ToolItem perspectiveButton = new ToolItem(swtToolbar, SWT.DROP_DOWN, 7);
    perspectiveButton.setImage(GUIResource.getInstance().getImage("ui/images/perspective_changer.svg"));
    perspectiveButton.setToolTipText(BaseMessages.getString(PKG, "Spoon.Menu.View.Perspectives"));
    perspectiveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Menu menu = new Menu(shell);
            for (final PerspectiveData perspectiveData : perspectiveList) {
                MenuItem item = new MenuItem(menu, SWT.CHECK);
                if (perspectiveData.isHidden()) {
                    item.setEnabled(false);
                }
                if (activePerspective.getId().equals(perspectiveData.getId())) {
                    item.setSelection(true);
                }
                item.setText(perspectiveData.getName());
                item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent selectionEvent) {
                        Spoon.getInstance().loadPerspective(perspectiveData.getId());
                        swtToolbar.forceFocus();
                    }
                });
            }
            ToolItem item = (ToolItem) e.widget;
            Rectangle rect = item.getBounds();
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y + rect.height));
            menu.setLocation(pt.x, pt.y);
            menu.setVisible(true);
        }
    });
    for (final SpoonPerspective per : getPerspectives()) {
        if (installedPerspectives.contains(per)) {
            y++;
            continue;
        }
        String name = per.getDisplayName(LanguageChoice.getInstance().getDefaultLocale());
        PerspectiveData perspectiveData = new PerspectiveData(name, per.getId());
        if (Arrays.asList(defaultDisabled).contains(per.getId())) {
            perspectiveData.setHidden(true);
        }
        perspectiveList.add(perspectiveData);
        XulVbox box = deck.createVBoxCard();
        box.setId("perspective-" + per.getId());
        box.setFlex(1);
        deck.addChild(box);
        PerspectiveManager perspectiveManager = new PerspectiveManager(per, box, mainToolbar, perspectiveList, name);
        perspectiveManagerMap.put(per, perspectiveManager);
        // Need to force init for main perspective even if it won't be shown
        if (perspectiveIdx == y || y == 0) {
            if (perspectiveIdx == y) {
                // we have a startup perspective. Hold onto the class
                perClass = per.getClass();
            }
            // force init
            perspectiveManager.initializeIfNeeded();
        }
        y++;
        installedPerspectives.add(per);
    }
    deck.setSelectedIndex(perspectiveIdx);
    if (perClass != null) {
        // activate the startup perspective
        try {
            activatePerspective(perClass);
            // stop other perspectives from opening
            SpoonPerspectiveManager.getInstance().setForcePerspective(true);
        } catch (KettleException e) {
        // TODO Auto-generated catch block
        }
    }
}
Also used : SwtDeck(org.pentaho.ui.xul.swt.tags.SwtDeck) XulVbox(org.pentaho.ui.xul.containers.XulVbox) KettleException(org.pentaho.di.core.exception.KettleException) XulToolbar(org.pentaho.ui.xul.containers.XulToolbar) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

ArrayList (java.util.ArrayList)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1 Shell (org.eclipse.swt.widgets.Shell)1 ToolBar (org.eclipse.swt.widgets.ToolBar)1 ToolItem (org.eclipse.swt.widgets.ToolItem)1 KettleException (org.pentaho.di.core.exception.KettleException)1 XulToolbar (org.pentaho.ui.xul.containers.XulToolbar)1 XulVbox (org.pentaho.ui.xul.containers.XulVbox)1 SwtDeck (org.pentaho.ui.xul.swt.tags.SwtDeck)1