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
}
}
}
Aggregations