Skip to content

Commit

Permalink
MONDRIAN: added simple plugin api for menu items in workbench
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 10809]
  • Loading branch information
Will Gorman committed Apr 3, 2008
1 parent d24bb4e commit 950b4b1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
80 changes: 76 additions & 4 deletions src/main/mondrian/gui/Workbench.java
Expand Up @@ -114,7 +114,8 @@ public Workbench() {
loadWorkbenchProperties();
initDataSource();
initComponents();

loadMenubarPlugins();

ImageIcon icon = new javax.swing.ImageIcon(myClassLoader.getResource(resourceConverter.getGUIReference("cube")));

this.setIconImage(icon.getImage());
Expand All @@ -141,10 +142,31 @@ private void loadWorkbenchProperties() {
}
}

/**
* returns the value of a workbench property
*
* @param key key to lookup
* @return the value
*/
public String getWorkbenchProperty(String key) {
return workbenchProperties.getProperty(key);
}

/**
* set a workbench property. Note that this does not save the property,
* a call to storeWorkbenchProperties is required.
*
* @param key property key
* @param value property value
*/
public void setWorkbenchProperty(String key, String value) {
workbenchProperties.setProperty(key, value);
}

/**
* save properties
*/
private void storeWorkbenchProperties() {
public void storeWorkbenchProperties() {
//save properties to file
File dir = new File(WORKBENCH_USER_HOME_DIR);
try {
Expand Down Expand Up @@ -588,6 +610,42 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
pack();
}

/**
* this method loads any available menubar plugins based on
*
*/
private void loadMenubarPlugins() {
// render any plugins
InputStream pluginStream = null;
try {
Properties props = new Properties();
pluginStream =
getClass().getResourceAsStream("/workbench_plugins.properties");
if (pluginStream != null) {
props.load(pluginStream);
for (Object key : props.keySet()) {
String keystr = (String)key;
if (keystr.startsWith("workbench.menu-plugin")) {
String val = props.getProperty(keystr);
WorkbenchMenubarPlugin plugin =
(WorkbenchMenubarPlugin)Class.forName(val).newInstance();
plugin.setWorkbench(this);
plugin.addItemsToMenubar(menuBar);
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (pluginStream != null) {
pluginStream.close();
}
} catch (Exception e) {}
}
}


/**
* @return the workbenchResourceBundle
*/
Expand Down Expand Up @@ -1018,7 +1076,21 @@ private void updateMDXCatalogList() {
}
}


/**
* returns the currently selected schema explorer object
*
* @return current schema explorer object
*/
public SchemaExplorer getCurrentSchemaExplorer() {
JInternalFrame jf = desktopPane.getSelectedFrame();
if (jf != null &&
jf.getContentPane().getComponentCount() > 0 &&
jf.getContentPane().getComponent(0) instanceof SchemaExplorer) {
return (SchemaExplorer) jf.getContentPane().getComponent(0);
}
return null;
}

private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JInternalFrame jf = desktopPane.getSelectedFrame();

Expand Down Expand Up @@ -1087,7 +1159,7 @@ private void viewXMLMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
viewXMLMenuItem.setSelected(! oldValue);
}

private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
public void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JInternalFrame jf = desktopPane.getSelectedFrame();

// Don't save if nothing there
Expand Down
8 changes: 8 additions & 0 deletions src/main/mondrian/gui/WorkbenchMenubarPlugin.java
@@ -0,0 +1,8 @@
package mondrian.gui;

import javax.swing.JMenuBar;

public interface WorkbenchMenubarPlugin {
public void addItemsToMenubar(JMenuBar menubar);
public void setWorkbench(Workbench workbench);
}

0 comments on commit 950b4b1

Please sign in to comment.