01: /*
02: * ScriptDbObjectAction.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.actions;
13:
14: import java.awt.event.ActionEvent;
15: import java.util.List;
16: import javax.swing.ListSelectionModel;
17: import javax.swing.SwingUtilities;
18: import javax.swing.event.ListSelectionEvent;
19: import javax.swing.event.ListSelectionListener;
20: import workbench.db.DbObject;
21: import workbench.db.ObjectScripter;
22: import workbench.gui.WbSwingUtilities;
23: import workbench.gui.dbobjects.DbObjectList;
24: import workbench.gui.dbobjects.ObjectScripterUI;
25: import workbench.resource.ResourceMgr;
26:
27: /**
28: * @author support@sql-workbench.net
29: */
30: public class ScriptDbObjectAction extends WbAction implements
31: ListSelectionListener {
32: private DbObjectList source;
33: private ListSelectionModel selection;
34:
35: public ScriptDbObjectAction(DbObjectList client,
36: ListSelectionModel list) {
37: this .initMenuDefinition("MnuTxtCreateScript");
38: this .source = client;
39: this .selection = list;
40: setEnabled(false);
41: setIcon(ResourceMgr.getImage("script"));
42: list.addListSelectionListener(this );
43: }
44:
45: @Override
46: public void executeAction(ActionEvent e) {
47: if (!WbSwingUtilities.checkConnection(source.getComponent(),
48: source.getConnection()))
49: return;
50:
51: List<? extends DbObject> objects = source.getSelectedObjects();
52: if (objects == null || objects.size() == 0)
53: return;
54:
55: ObjectScripter s = new ObjectScripter(objects, source
56: .getConnection());
57: ObjectScripterUI scripterUI = new ObjectScripterUI(s);
58: scripterUI.show(SwingUtilities.getWindowAncestor(source
59: .getComponent()));
60: }
61:
62: public void valueChanged(ListSelectionEvent e) {
63: setEnabled(this .selection.getMinSelectionIndex() >= 0);
64: }
65:
66: }
|