Skip to content

Commit

Permalink
Add Explorer in view menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Mar 29, 2015
1 parent 3bdaa75 commit 4afe95a
Showing 1 changed file with 70 additions and 35 deletions.
Expand Up @@ -29,7 +29,6 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -44,7 +43,6 @@
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
Expand All @@ -64,8 +62,6 @@
import javax.swing.TransferHandler;
import javax.swing.WindowConstants;

import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.weasis.base.ui.Messages;
Expand All @@ -88,7 +84,6 @@
import org.weasis.core.api.media.data.MediaSeriesGroup;
import org.weasis.core.api.media.data.Series;
import org.weasis.core.api.media.data.TagW;
import org.weasis.core.api.service.BundlePreferences;
import org.weasis.core.api.service.BundleTools;
import org.weasis.core.api.util.ResourceUtil;
import org.weasis.core.api.util.StringUtil;
Expand Down Expand Up @@ -784,6 +779,35 @@ public void actionPerformed(ActionEvent e) {
}
}

private static void buildEplorerSubMenu(final JMenu explorerMenu) {
synchronized (UIManager.EXPLORER_PLUGINS) {
List<DataExplorerView> explorers = UIManager.EXPLORER_PLUGINS;
for (final DataExplorerView dataExplorerView : explorers) {
if (dataExplorerView instanceof DockableTool) {
final DockableTool t = (DockableTool) dataExplorerView;
if (!Insertable.Type.EMPTY.equals(t.getType())) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(t.getComponentName(), t.isComponentEnabled());
item.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JCheckBoxMenuItem) {
t.setComponentEnabled(((JCheckBoxMenuItem) e.getSource()).isSelected());
if (t.isComponentEnabled()) {
t.showDockable();
} else {
t.closeDockable();
}
}
}
});
explorerMenu.add(item);
}
}
}
}
}

private static void buildPrintSubMenu(final JMenu printMenu) {
if (selectedPlugin != null) {
List<Action> actions = selectedPlugin.getPrintActions();
Expand Down Expand Up @@ -883,41 +907,52 @@ public void popupMenuWillBecomeVisible() {
toolMenu.addPopupMenuListener();
menuView.add(toolMenu);

// TODO add save workspace layout
final AbstractAction saveAction = new AbstractAction("Save workspace layout") { //$NON-NLS-1$
DynamicMenu explorerMenu = new DynamicMenu("Explorer") { //$NON-NLS-1$

@Override
public void actionPerformed(ActionEvent e) {
// Handle workspace ui persistence
try {
UIManager.DOCKING_CONTROL.save("lastLayout");
final BundleContext context = FrameworkUtil.getBundle(WeasisWin.class).getBundleContext();
File file = new File(BundlePreferences.getDataFolder(context), "lastLayout.xml");
UIManager.DOCKING_CONTROL.writeXML(file);
} catch (IOException e1) {
e1.printStackTrace();
}
public void popupMenuWillBecomeVisible() {
buildEplorerSubMenu(this);
}
};
menuView.add(saveAction);

final AbstractAction loadAction = new AbstractAction("Restore last workspace layout") { //$NON-NLS-1$

@Override
public void actionPerformed(ActionEvent e) {
try {
final BundleContext context = FrameworkUtil.getBundle(WeasisWin.class).getBundleContext();
File file = new File(BundlePreferences.getDataFolder(context), "lastLayout.xml");
if (file.canRead()) {
UIManager.DOCKING_CONTROL.readXML(file);
UIManager.DOCKING_CONTROL.load("lastLayout");
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
};
menuView.add(loadAction);
explorerMenu.addPopupMenuListener();
menuView.add(explorerMenu);

// TODO add save workspace layout
// final AbstractAction saveAction = new AbstractAction("Save workspace layout") { //$NON-NLS-1$
//
// @Override
// public void actionPerformed(ActionEvent e) {
// // Handle workspace ui persistence
// try {
// UIManager.DOCKING_CONTROL.save("lastLayout", false);
// final BundleContext context = FrameworkUtil.getBundle(WeasisWin.class).getBundleContext();
// File file = new File(BundlePreferences.getDataFolder(context), "lastLayout.xml");
// UIManager.DOCKING_CONTROL.writeXML(file);
// } catch (IOException e1) {
// e1.printStackTrace();
// }
// }
// };
// menuView.add(saveAction);
//
// final AbstractAction loadAction = new AbstractAction("Restore last workspace layout") { //$NON-NLS-1$
//
// @Override
// public void actionPerformed(ActionEvent e) {
// try {
// final BundleContext context = FrameworkUtil.getBundle(WeasisWin.class).getBundleContext();
// File file = new File(BundlePreferences.getDataFolder(context), "lastLayout.xml");
// if (file.canRead()) {
// UIManager.DOCKING_CONTROL.readXML(file);
// UIManager.DOCKING_CONTROL.load("lastLayout", false);
// }
// } catch (IOException e1) {
// e1.printStackTrace();
// }
// }
// };
// menuView.add(loadAction);
}

private static void buildMenuFile() {
Expand Down

0 comments on commit 4afe95a

Please sign in to comment.