KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > properties > PropertyPage


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

5 package org.terracotta.dso.properties;
6
7 import org.eclipse.core.resources.IFolder;
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.IResource;
10 import org.eclipse.jdt.core.IJavaProject;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.events.SelectionAdapter;
13 import org.eclipse.swt.events.SelectionEvent;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.Group;
21 import org.eclipse.swt.widgets.Text;
22 import org.terracotta.dso.TcPlugin;
23 import org.terracotta.dso.editors.chooser.ProjectFileNavigator;
24
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27
28 import javax.swing.SwingUtilities JavaDoc;
29
30 public final class PropertyPage extends org.eclipse.ui.dialogs.PropertyPage {
31   private final Display m_display;
32   private Text m_configPathField;
33   private Button m_configFileButton;
34   private ProjectFileNavigator m_fileNavigator;
35   private Text m_serverOptionsField;
36   private Button m_resetOptionsButton;
37
38   private static final String JavaDoc DEFAULT_CONFIG_FILENAME = TcPlugin.DEFAULT_CONFIG_FILENAME;
39   private static final String JavaDoc DEFAULT_SERVER_OPTIONS = TcPlugin.DEFAULT_SERVER_OPTIONS;
40
41   public PropertyPage() {
42     super();
43     m_display = Display.getCurrent();
44   }
45
46   private void fillControls() {
47     TcPlugin plugin = TcPlugin.getDefault();
48     IProject project = getProject();
49     m_configPathField.setText(plugin.getConfigurationFilePath(project));
50     m_serverOptionsField.setText(plugin.getServerOptions(project));
51   }
52
53   protected Control createContents(Composite parent) {
54     final Composite topComp = new Composite(parent, SWT.NONE);
55     GridLayout gridLayout = new GridLayout();
56     gridLayout.numColumns = 1;
57     gridLayout.makeColumnsEqualWidth = false;
58     topComp.setLayout(gridLayout);
59     topComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60
61     Group domainConfig = new Group(topComp, SWT.SHADOW_ETCHED_IN);
62     domainConfig.setText("Domain Configuration");
63     gridLayout = new GridLayout();
64     gridLayout.numColumns = 2;
65     domainConfig.setLayout(gridLayout);
66     domainConfig.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
67
68     m_configPathField = new Text(domainConfig, SWT.SINGLE | SWT.BORDER);
69     m_configPathField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
70
71     m_configFileButton = new Button(domainConfig, SWT.PUSH);
72     m_configFileButton.setText(" Browse... ");
73     m_configFileButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
74     m_configFileButton.addSelectionListener(new SelectionAdapter() {
75       public void widgetSelected(SelectionEvent e) {
76         if (m_fileNavigator == null) {
77           m_fileNavigator = new ProjectFileNavigator(null, "xml");
78           m_fileNavigator.setActionListener(new NavigatorListener());
79         }
80         m_fileNavigator.init(getProject());
81         m_fileNavigator.center();
82         m_display.asyncExec(new Runnable JavaDoc() {
83           public void run() {
84             m_fileNavigator.setVisible(true);
85             m_fileNavigator.toFront();
86             m_fileNavigator.setAlwaysOnTop(true);
87           }
88         });
89       }
90     });
91
92     Group serverOptions = new Group(topComp, SWT.SHADOW_ETCHED_IN);
93     serverOptions.setText("Server Options");
94     gridLayout = new GridLayout();
95     gridLayout.numColumns = 2;
96     serverOptions.setLayout(gridLayout);
97     GridData gridData = new GridData();
98     gridData.horizontalAlignment = GridData.FILL;
99     gridData.heightHint = 60;
100     serverOptions.setLayoutData(gridData);
101
102     m_serverOptionsField = new Text(serverOptions, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
103     GridData gd = new GridData(GridData.FILL_BOTH);
104     m_serverOptionsField.setLayoutData(gd);
105
106     m_resetOptionsButton = new Button(serverOptions, SWT.PUSH);
107     m_resetOptionsButton.setText(" Reset ");
108     m_resetOptionsButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_BEGINNING));
109     m_resetOptionsButton.addSelectionListener(new SelectionAdapter() {
110       public void widgetSelected(SelectionEvent e) {
111         m_serverOptionsField.setText(DEFAULT_SERVER_OPTIONS);
112       }
113     });
114
115     Composite composite = new Composite(topComp, SWT.EMBEDDED);
116     composite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
117     fillControls();
118     return topComp;
119   }
120
121   class NavigatorListener implements ActionListener JavaDoc {
122     public void actionPerformed(ActionEvent JavaDoc e) {
123       SwingUtilities.invokeLater(new Runnable JavaDoc() {
124         public void run() {
125           IResource member = m_fileNavigator.getSelectedMember();
126           if (member != null) {
127             if (member instanceof IFolder) {
128               member = ((IFolder) member).getFile(TcPlugin.DEFAULT_CONFIG_FILENAME);
129             }
130             final IResource finalMember = member;
131             m_display.asyncExec(new Runnable JavaDoc() {
132               public void run() {
133                 m_configPathField.setText(finalMember.getProjectRelativePath().toString());
134               }
135             });
136           }
137         }
138       });
139     }
140   }
141
142   protected void performDefaults() {
143     m_configPathField.setText(DEFAULT_CONFIG_FILENAME);
144     m_serverOptionsField.setText(DEFAULT_SERVER_OPTIONS);
145   }
146
147   private IProject getProject() {
148     return ((IJavaProject) getElement()).getProject();
149   }
150
151   private void updateProject() {
152     TcPlugin plugin = TcPlugin.getDefault();
153     IProject project = getProject();
154     plugin.setup(project, m_configPathField.getText(), m_serverOptionsField.getText());
155   }
156
157   public boolean performOk() {
158     updateProject();
159     return true;
160   }
161 }
162
Popular Tags