Search in sources :

Example 1 with XulToolbar

use of org.pentaho.ui.xul.containers.XulToolbar in project pentaho-kettle by pentaho.

the class SpoonMenuABSController method updateMenu.

public void updateMenu(Document doc) {
    try {
        Spoon spoon = Spoon.getInstance();
        boolean createPermitted = true;
        boolean executePermitted = true;
        // If we are working with an Enterprise Repository
        if ((spoon != null) && (spoon.getRepository() != null) && (spoon.getRepository() instanceof PurRepository)) {
            Repository repo = spoon.getRepository();
            // Check for ABS Security
            if (repo.hasService(IAbsSecurityProvider.class)) {
                IAbsSecurityProvider securityProvider = (IAbsSecurityProvider) repo.getService(IAbsSecurityProvider.class);
                // Get create & execute permission
                createPermitted = securityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
                executePermitted = securityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
                EngineMetaInterface meta = spoon.getActiveMeta();
                // If (meta is not null) and (meta is either a Transformation or Job)
                if ((meta != null) && ((meta instanceof JobMeta) || (meta instanceof TransMeta))) {
                    // Main spoon toolbar
                    // $NON-NLS-1$
                    ((XulToolbarbutton) doc.getElementById("toolbar-file-new")).setDisabled(!createPermitted);
                    // $NON-NLS-1$
                    ((XulToolbarbutton) doc.getElementById("toolbar-file-save")).setDisabled(!createPermitted);
                    // $NON-NLS-1$
                    ((XulToolbarbutton) doc.getElementById("toolbar-file-save-as")).setDisabled(!createPermitted);
                    // Popup menus
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("trans-class-new")).setDisabled(!createPermitted);
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("job-class-new")).setDisabled(!createPermitted);
                    // Main spoon menu
                    // $NON-NLS-1$
                    ((XulMenu) doc.getElementById("file-new")).setDisabled(!createPermitted);
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("file-save")).setDisabled(!createPermitted);
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("file-save-as")).setDisabled(!createPermitted);
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("file-close")).setDisabled(!createPermitted);
                }
                // Handle Execute permissions
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("process-run")).setDisabled(!executePermitted);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("trans-preview")).setDisabled(!executePermitted);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("trans-debug")).setDisabled(!executePermitted);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("trans-replay")).setDisabled(!executePermitted);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("trans-verify")).setDisabled(!executePermitted);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("trans-impact")).setDisabled(!executePermitted);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("trans-get-sql")).setDisabled(!executePermitted);
                // Disable Show Last menu under the Action menu. Disable without execute permissions.
                // $NON-NLS-1$
                ((XulMenu) doc.getElementById("trans-last")).setDisabled(!executePermitted);
                boolean exportAllowed = createPermitted && executePermitted;
                // $NON-NLS-1$
                ((XulMenu) doc.getElementById("file-export")).setDisabled(!exportAllowed);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("repository-export-all")).setDisabled(!exportAllowed);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("file-save-as-vfs")).setDisabled(!exportAllowed);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("edit-cut-steps")).setDisabled(!exportAllowed);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("edit-copy-steps")).setDisabled(!exportAllowed);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("edit.copy-file")).setDisabled(!exportAllowed);
                // $NON-NLS-1$
                ((XulMenuitem) doc.getElementById("edit-paste-steps")).setDisabled(!exportAllowed);
                // Schedule is a plugin
                if (doc.getElementById("trans-schedule") != null) {
                    // $NON-NLS-1$
                    ((XulMenuitem) doc.getElementById("trans-schedule")).setDisabled(!executePermitted);
                }
                TransGraph transGraph = Spoon.getInstance().getActiveTransGraph();
                if (transGraph != null) {
                    XulToolbar toolbar = transGraph.getToolbar();
                    XulToolbarbutton runButton = (XulToolbarbutton) toolbar.getElementById("trans-run");
                    XulToolbarbutton debugButton = (XulToolbarbutton) toolbar.getElementById("trans-debug");
                    XulToolbarbutton previewButton = (XulToolbarbutton) toolbar.getElementById("trans-preview");
                    XulToolbarbutton replayButton = (XulToolbarbutton) toolbar.getElementById("trans-replay");
                    XulToolbarbutton verifyButton = (XulToolbarbutton) toolbar.getElementById("trans-verify");
                    XulToolbarbutton impactButton = (XulToolbarbutton) toolbar.getElementById("trans-impact");
                    XulToolbarbutton generateSqlButton = (XulToolbarbutton) toolbar.getElementById("trans-get-sql");
                    if ((runButton != null) && (runButton.isDisabled() ^ !executePermitted)) {
                        runButton.setDisabled(!executePermitted);
                    }
                    if ((debugButton != null) && (debugButton.isDisabled() ^ !executePermitted)) {
                        debugButton.setDisabled(!executePermitted);
                    }
                    if ((previewButton != null) && (previewButton.isDisabled() ^ !executePermitted)) {
                        previewButton.setDisabled(!executePermitted);
                    }
                    if ((replayButton != null) && (replayButton.isDisabled() ^ !executePermitted)) {
                        replayButton.setDisabled(!executePermitted);
                    }
                    if ((verifyButton != null) && (verifyButton.isDisabled() ^ !executePermitted)) {
                        verifyButton.setDisabled(!executePermitted);
                    }
                    if ((impactButton != null) && (impactButton.isDisabled() ^ !executePermitted)) {
                        impactButton.setDisabled(!executePermitted);
                    }
                    if ((generateSqlButton != null) && (generateSqlButton.isDisabled() ^ !executePermitted)) {
                        generateSqlButton.setDisabled(!executePermitted);
                    }
                }
                JobGraph jobGraph = Spoon.getInstance().getActiveJobGraph();
                if (jobGraph != null) {
                    XulToolbar toolbar = jobGraph.getToolbar();
                    XulToolbarbutton runButton = (XulToolbarbutton) toolbar.getElementById("job-run");
                    XulToolbarbutton generateSqlButton = (XulToolbarbutton) toolbar.getElementById("job-get-sql");
                    if ((runButton != null) && (runButton.isDisabled() ^ !executePermitted)) {
                        runButton.setDisabled(!executePermitted);
                    }
                    if ((generateSqlButton != null) && (generateSqlButton.isDisabled() ^ !executePermitted)) {
                        generateSqlButton.setDisabled(!executePermitted);
                    }
                }
            }
        }
        EESpoonPlugin.updateChangedWarningDialog(createPermitted);
    } catch (Exception e) {
        // don't let this bomb all the way out, otherwise we'll get stuck: PDI-4670
        log.logError(e.getMessage(), e);
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) JobMeta(org.pentaho.di.job.JobMeta) XulToolbar(org.pentaho.ui.xul.containers.XulToolbar) PurRepository(org.pentaho.di.repository.pur.PurRepository) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) XulToolbarbutton(org.pentaho.ui.xul.components.XulToolbarbutton) XulMenu(org.pentaho.ui.xul.containers.XulMenu) Repository(org.pentaho.di.repository.Repository) PurRepository(org.pentaho.di.repository.pur.PurRepository) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) Spoon(org.pentaho.di.ui.spoon.Spoon) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface)

Example 2 with XulToolbar

use of org.pentaho.ui.xul.containers.XulToolbar 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)

Example 3 with XulToolbar

use of org.pentaho.ui.xul.containers.XulToolbar in project pentaho-kettle by pentaho.

the class SpoonPerspectiveManager method removePerspective.

public void removePerspective(SpoonPerspective per) {
    perspectives.remove(per);
    orderedPerspectives.remove(per);
    Document document = domContainer.getDocumentRoot();
    XulComponent comp = document.getElementById("perspective-" + per.getId());
    comp.getParent().removeChild(comp);
    comp = document.getElementById("perspective-btn-" + per.getId());
    comp.getParent().removeChild(comp);
    XulToolbar mainToolbar = (XulToolbar) domContainer.getDocumentRoot().getElementById("main-toolbar");
    ((Composite) mainToolbar.getManagedObject()).layout(true, true);
    deck.setSelectedIndex(0);
}
Also used : XulToolbar(org.pentaho.ui.xul.containers.XulToolbar) Composite(org.eclipse.swt.widgets.Composite) Document(org.pentaho.ui.xul.dom.Document) XulComponent(org.pentaho.ui.xul.XulComponent)

Example 4 with XulToolbar

use of org.pentaho.ui.xul.containers.XulToolbar in project pentaho-kettle by pentaho.

the class RepositorySpoonPlugin method applyToContainer.

@Override
public void applyToContainer(String category, XulDomContainer container) throws XulException {
    if ((category.equals(SPOON_CATEGORY) && !Const.isRunningOnWebspoonMode())) {
        XulToolbar toolbar = (XulToolbar) container.getDocumentRoot().getElementById("main-toolbar");
        RepositoryConnectMenu repoConnectMenu = new RepositoryConnectMenu(Spoon.getInstance(), (ToolBar) toolbar.getManagedObject(), repositoryConnectController);
        repoConnectMenu.render();
    }
}
Also used : XulToolbar(org.pentaho.ui.xul.containers.XulToolbar) RepositoryConnectMenu(org.pentaho.di.ui.repo.menu.RepositoryConnectMenu)

Aggregations

XulToolbar (org.pentaho.ui.xul.containers.XulToolbar)4 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 Composite (org.eclipse.swt.widgets.Composite)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 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)1 KettleException (org.pentaho.di.core.exception.KettleException)1 JobMeta (org.pentaho.di.job.JobMeta)1 Repository (org.pentaho.di.repository.Repository)1 PurRepository (org.pentaho.di.repository.pur.PurRepository)1 TransMeta (org.pentaho.di.trans.TransMeta)1 RepositoryConnectMenu (org.pentaho.di.ui.repo.menu.RepositoryConnectMenu)1 IAbsSecurityProvider (org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider)1