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);
}
}
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
}
}
}
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);
}
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();
}
}
Aggregations