KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > workflowadmin > definition > SelectPackage


1 package org.enhydra.shark.corbaclient.workflowadmin.definition;
2
3 import org.omg.WfBase.*;
4 import java.awt.*;
5 import java.awt.event.*;
6
7 import javax.swing.*;
8 import javax.swing.border.*;
9 import javax.swing.event.*;
10
11 import org.enhydra.shark.corbaclient.workflowadmin.definition.actions.*;
12
13 import org.enhydra.shark.corbaclient.*;
14
15 /**
16 * The dialog that enables user to open one of defined packages.
17 */

18 public class SelectPackage extends ActionPanel {
19
20    private static Dimension listFieldDimension=new Dimension(400,400);
21
22    private JList packages;
23    private JTextField pkg=new JTextField();
24
25    private String JavaDoc applicationId;
26    private String JavaDoc packageName;
27
28    private java.util.List JavaDoc allPackages;
29
30    private ActionBase myOwner;
31
32    public SelectPackage (ActionBase ab,Window w,java.util.List JavaDoc allPackages) {
33       super();
34       // First init allPackages, and then call super.init()
35
this.allPackages=allPackages;
36       this.myOwner=ab;
37       super.init();
38       String JavaDoc dialogTitle;
39       String JavaDoc okB, cB;
40       if (ab instanceof LoadPackage) {
41          dialogTitle=ResourceManager.getLanguageDependentString("DialogLoadPackage");
42          okB=ResourceManager.getLanguageDependentString("LoadKey");
43          cB=ResourceManager.getLanguageDependentString("CloseKey");
44       } else {
45          dialogTitle=ResourceManager.getLanguageDependentString("DialogUpdatePackage");
46          okB=ResourceManager.getLanguageDependentString("UpdateKey");
47          cB=ResourceManager.getLanguageDependentString("CancelKey");
48       }
49       super.initDialog(w,dialogTitle,true,true);
50       dialogOKButton.setText(okB);
51       dialogCancelButton.setText(cB);
52    }
53
54    protected void createActions () {}
55
56    protected Component createCenterComponent() {
57       pkg.setEnabled(false);
58
59       JScrollPane scrollPackages=new JScrollPane();
60       if (allPackages==null) {
61          packages=new JList();
62       } else {
63          String JavaDoc[] aps=new String JavaDoc[allPackages.size()];
64          for (int i=0; i<allPackages.size(); i++) {
65             aps[i]=((NameValueStringMap)allPackages.get(i)).name;
66          }
67          packages=new JList(aps);
68       }
69       packages.addListSelectionListener(new ListSelectionListener() {
70          public void valueChanged(ListSelectionEvent e) {
71             if (e.getValueIsAdjusting()) {
72                return;
73             }
74
75             JList theList = (JList)e.getSource();
76             if (theList.isSelectionEmpty()) {
77                pkg.setText("");
78             } else {
79                int selInd=theList.getSelectedIndex();
80                String JavaDoc mn = (String JavaDoc)theList.getSelectedValue()+", Id="+
81                      ((NameValueStringMap)allPackages.get(selInd)).value;
82                pkg.setText(mn);
83             }
84          }
85       });
86       // mouse listener for invoking LoadPackage on double-click
87
packages.addMouseListener(new MouseAdapter() {
88          public void mouseClicked (MouseEvent me) {
89             if (me.getClickCount()>1) {
90                applyChanges();
91             }
92          }
93       });
94
95       packages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
96       scrollPackages.setViewportView(packages);
97       scrollPackages.setPreferredSize(new Dimension(listFieldDimension));
98
99       JPanel pm=new JPanel();
100       Border emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
101       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
102       inb=BorderFactory.createTitledBorder(inb,
103          ResourceManager.getLanguageDependentString("SelectPackageKey"));
104       pm.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
105       pm.setLayout(new BoxLayout(pm,BoxLayout.Y_AXIS));
106       pm.add(scrollPackages);
107       pm.add(pkg);
108
109       return pm;
110    }
111
112    protected void applyChanges () {
113       if (packages.isSelectionEmpty()) {
114          packageName=null;
115       } else {
116          try {
117             packageName=(String JavaDoc)packages.getSelectedValue();
118          } catch (Exception JavaDoc ex){}
119       }
120
121       if (packageName==null) return;
122       if (myOwner instanceof LoadPackage) {
123          ((LoadPackage)myOwner).loadPackage(packageName);
124       } else {
125          int selInd=packages.getSelectedIndex();
126          String JavaDoc pkgId=((NameValueStringMap)allPackages.get(selInd)).value;
127          ((UpdatePackage)myOwner).updatePackage(pkgId,packageName);
128          myDialog.dispose();
129       }
130       requestFocus();
131    }
132
133    protected void cancelChanges () {
134       myDialog.dispose();
135    }
136
137    public String JavaDoc getSelectedPackage () {
138       return packageName;
139    }
140
141 }
142
143
Popular Tags