KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > dialogs > LockAttributesDialog


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.dialogs;
5
6 import org.dijon.ButtonGroup;
7 import org.dijon.Container;
8 import org.dijon.ContainerResource;
9 import org.dijon.DictionaryResource;
10 import org.dijon.TextField;
11 import org.eclipse.jdt.core.IJavaElement;
12 import org.eclipse.jface.dialogs.IDialogConstants;
13 import org.eclipse.jface.dialogs.MessageDialog;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.awt.SWT_AWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Shell;
20 import org.terracotta.dso.PatternHelper;
21 import org.terracotta.dso.TcPlugin;
22
23 import com.tc.admin.common.XAbstractAction;
24 import com.terracottatech.config.LockLevel;
25
26 import java.awt.BorderLayout JavaDoc;
27 import java.awt.Frame JavaDoc;
28 import java.awt.Panel JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.KeyEvent JavaDoc;
31
32 import javax.swing.InputMap JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JRootPane JavaDoc;
35 import javax.swing.KeyStroke JavaDoc;
36
37 /**
38  * Given an IMethod display a form letting the user specify the lock's name and level.
39  */

40
41 public class LockAttributesDialog extends MessageDialog {
42   private static ContainerResource m_panelRes;
43   
44   private TextField m_nameField;
45   private ButtonGroup m_typeGroup;
46   private IJavaElement m_element;
47   
48   private static final String JavaDoc ENTER_CMD = "ENTER";
49   
50   static {
51     DictionaryResource topRes = TcPlugin.getDefault().getResources();
52     m_panelRes = (ContainerResource)topRes.findComponent("LockAttributesPanel");
53   }
54   
55   public LockAttributesDialog(Shell parentShell, IJavaElement element) {
56     super(parentShell, "Specify Named-Lock Attributes", null,
57           PatternHelper.getExecutionPattern(element),
58           MessageDialog.NONE,
59           new String JavaDoc[] {IDialogConstants.OK_LABEL,
60                         IDialogConstants.CANCEL_LABEL}, 0);
61     m_element = element;
62   }
63   
64   protected Control createCustomArea(Composite parent) {
65     Composite composite = new Composite(parent, SWT.EMBEDDED);
66     
67     composite.setLayoutData(new GridData(GridData.FILL_BOTH));
68
69     Frame JavaDoc frame = SWT_AWT.new_Frame(composite);
70   
71     JRootPane JavaDoc rootPane = new JRootPane JavaDoc();
72     Panel JavaDoc root = new Panel JavaDoc(new BorderLayout JavaDoc());
73     Container panel = new Container(m_panelRes);
74
75     frame.add(root);
76     root.add(rootPane);
77     rootPane.getContentPane().add(panel);
78
79     m_nameField = (TextField)panel.findComponent("NameField");
80     m_nameField.setText(m_element.getElementName());
81     
82     m_typeGroup = (ButtonGroup)panel.findComponent("TypeGroup");
83     m_typeGroup.setSelectedIndex(1);
84
85     panel.getActionMap().put(ENTER_CMD, new XAbstractAction() {
86       public void actionPerformed(ActionEvent JavaDoc ae) {
87         acceptValues();
88       }
89     });
90     
91     InputMap JavaDoc inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
92     inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), ENTER_CMD);
93
94     frame.setVisible(true);
95
96     return composite;
97   }
98   
99   private void acceptValues() {
100     getShell().getDisplay().syncExec(new Runnable JavaDoc() {
101       public void run(){
102         buttonPressed(IDialogConstants.OK_ID);
103       }
104     });
105   }
106   
107   /*
108    * Return the user-specified lock name.
109    */

110   public String JavaDoc getLockName() {
111     return m_nameField.getText();
112   }
113   
114   /*
115    * Return the user-specified lock level:
116    * LockLevel.READ
117    * LockLevel.WRITE
118    */

119   public LockLevel.Enum getLockLevel() {
120     return "WriteButton".equals(m_typeGroup.getSelected()) ?
121         LockLevel.WRITE : LockLevel.READ;
122   }
123 }
124
Popular Tags