001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.dso.properties;
006:
007: import org.eclipse.core.resources.IProject;
008: import org.eclipse.jdt.core.IJavaProject;
009: import org.eclipse.swt.SWT;
010: import org.eclipse.swt.events.SelectionAdapter;
011: import org.eclipse.swt.events.SelectionEvent;
012: import org.eclipse.swt.layout.GridData;
013: import org.eclipse.swt.layout.GridLayout;
014: import org.eclipse.swt.widgets.Button;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.Control;
017: import org.eclipse.swt.widgets.Group;
018: import org.eclipse.swt.widgets.Text;
019: import org.terracotta.dso.TcPlugin;
020: import org.terracotta.dso.editors.chooser.ConfigFileBehavior;
021: import org.terracotta.dso.editors.chooser.NavigatorBehavior;
022: import org.terracotta.dso.editors.chooser.PackageNavigator;
023: import org.terracotta.ui.util.SWTUtil;
024:
025: import com.tc.util.event.UpdateEvent;
026: import com.tc.util.event.UpdateEventListener;
027:
028: public final class PropertyPage extends
029: org.eclipse.ui.dialogs.PropertyPage {
030: private static final String TERRACOTTA_CONFIG = "Terracotta Configuration";
031: private static final String BROWSE = "Browse...";
032: private static final String RESET = "Reset";
033: private static final String SERVER_OPTIONS = "Server Options";
034:
035: private Text m_configPathField;
036: private Button m_configFileButton;
037: private Text m_serverOptionsField;
038: private Button m_autoStartServerButton;
039: private Button m_warnConfigProblemsButton;
040: private Button m_queryRestartButton;
041: private Button m_resetOptionsButton;
042:
043: private static final String DEFAULT_CONFIG_FILENAME = TcPlugin.DEFAULT_CONFIG_FILENAME;
044: private static final String DEFAULT_SERVER_OPTIONS = TcPlugin.DEFAULT_SERVER_OPTIONS;
045: private static final boolean DEFAULT_AUTO_START_SERVER_OPTION = TcPlugin.DEFAULT_AUTO_START_SERVER_OPTION;
046: private static final boolean DEFAULT_WARN_CONFIG_PROBLEMS_OPTION = TcPlugin.DEFAULT_WARN_CONFIG_PROBLEMS_OPTION;
047: private static final boolean DEFAULT_QUERY_RESTART_OPTION = TcPlugin.DEFAULT_QUERY_RESTART_OPTION;
048:
049: private static final String AUTO_RESTART_SERVER_MSG = "Automatically start the Terracotta Server when necessary";
050: private static final String WARN_CONFIG_PROBLEMS_MSG = "Warn about config problems before launching a Terracotta process";
051: private static final String QUERY_RESTART_MSG = "When the config changes, offer to restart running Terracotta processes";
052:
053: private void fillControls() {
054: TcPlugin plugin = TcPlugin.getDefault();
055: IProject project = getProject();
056: m_configPathField.setText(plugin
057: .getConfigurationFilePath(project));
058: m_serverOptionsField.setText(plugin.getServerOptions(project));
059: m_autoStartServerButton.setSelection(plugin
060: .getAutoStartServerOption(project));
061: m_warnConfigProblemsButton.setSelection(plugin
062: .getWarnConfigProblemsOption(project));
063: m_queryRestartButton.setSelection(plugin
064: .getQueryRestartOption(project));
065: }
066:
067: protected Control createContents(Composite parent) {
068: final Composite topComp = new Composite(parent, SWT.NONE);
069: GridLayout gridLayout = new GridLayout();
070: gridLayout.numColumns = 1;
071: gridLayout.makeColumnsEqualWidth = false;
072: topComp.setLayout(gridLayout);
073: topComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
074:
075: Group domainConfig = new Group(topComp, SWT.NONE);
076: domainConfig.setText(TERRACOTTA_CONFIG);
077: gridLayout = new GridLayout();
078: gridLayout.numColumns = 2;
079: domainConfig.setLayout(gridLayout);
080: domainConfig.setLayoutData(new GridData(
081: GridData.FILL_HORIZONTAL));
082:
083: m_configPathField = new Text(domainConfig, SWT.SINGLE
084: | SWT.BORDER);
085: m_configPathField.setLayoutData(new GridData(
086: GridData.FILL_HORIZONTAL));
087:
088: m_configFileButton = new Button(domainConfig, SWT.PUSH);
089: m_configFileButton.setText(BROWSE);
090: m_configFileButton.setLayoutData(new GridData(
091: GridData.HORIZONTAL_ALIGN_END));
092: SWTUtil.applyDefaultButtonSize(m_configFileButton);
093: m_configFileButton.addSelectionListener(new SelectionAdapter() {
094: public void widgetSelected(SelectionEvent e) {
095: NavigatorBehavior behavior = new ConfigFileBehavior();
096: PackageNavigator dialog = new PackageNavigator(
097: getShell(), behavior.getTitle(), getProject(),
098: behavior);
099: dialog.addValueListener(new UpdateEventListener() {
100: public void handleUpdate(UpdateEvent event) {
101: m_configPathField.setText((String) event.data);
102: }
103: });
104: dialog.open();
105: }
106: });
107: Group serverOptions = new Group(topComp, SWT.NONE);
108: serverOptions.setText(SERVER_OPTIONS);
109: serverOptions.setLayout(new GridLayout(2, false));
110: GridData gridData = new GridData();
111: gridData.horizontalAlignment = GridData.FILL;
112: gridData.heightHint = 60;
113: serverOptions.setLayoutData(gridData);
114:
115: m_serverOptionsField = new Text(serverOptions, SWT.MULTI
116: | SWT.BORDER | SWT.V_SCROLL);
117: GridData gd = new GridData(GridData.FILL_BOTH);
118: m_serverOptionsField.setLayoutData(gd);
119:
120: m_resetOptionsButton = new Button(serverOptions, SWT.PUSH);
121: m_resetOptionsButton.setText(RESET);
122: SWTUtil.applyDefaultButtonSize(m_resetOptionsButton);
123: gd = (GridData) m_resetOptionsButton.getLayoutData();
124: gd.verticalAlignment = SWT.BEGINNING;
125: m_resetOptionsButton
126: .addSelectionListener(new SelectionAdapter() {
127: public void widgetSelected(SelectionEvent e) {
128: m_serverOptionsField
129: .setText(DEFAULT_SERVER_OPTIONS);
130: }
131: });
132:
133: m_autoStartServerButton = new Button(topComp, SWT.CHECK);
134: m_autoStartServerButton.setText(AUTO_RESTART_SERVER_MSG);
135: m_autoStartServerButton.setLayoutData(new GridData());
136:
137: m_warnConfigProblemsButton = new Button(topComp, SWT.CHECK);
138: m_warnConfigProblemsButton.setText(WARN_CONFIG_PROBLEMS_MSG);
139: m_warnConfigProblemsButton.setLayoutData(new GridData());
140:
141: m_queryRestartButton = new Button(topComp, SWT.CHECK);
142: m_queryRestartButton.setText(QUERY_RESTART_MSG);
143: m_queryRestartButton.setLayoutData(new GridData());
144:
145: Composite composite = new Composite(topComp, SWT.EMBEDDED);
146: composite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
147: fillControls();
148: return topComp;
149: }
150:
151: protected void performDefaults() {
152: m_configPathField.setText(DEFAULT_CONFIG_FILENAME);
153: m_serverOptionsField.setText(DEFAULT_SERVER_OPTIONS);
154: m_autoStartServerButton
155: .setSelection(DEFAULT_AUTO_START_SERVER_OPTION);
156: m_warnConfigProblemsButton
157: .setSelection(DEFAULT_WARN_CONFIG_PROBLEMS_OPTION);
158: m_queryRestartButton.setSelection(DEFAULT_QUERY_RESTART_OPTION);
159: }
160:
161: private IProject getProject() {
162: return ((IJavaProject) getElement()).getProject();
163: }
164:
165: private void updateProject() {
166: TcPlugin plugin = TcPlugin.getDefault();
167: IProject project = getProject();
168: plugin.setup(project, m_configPathField.getText(),
169: m_serverOptionsField.getText());
170: plugin.setAutoStartServerOption(project,
171: m_autoStartServerButton.getSelection());
172: plugin.setWarnConfigProblemsOption(project,
173: m_warnConfigProblemsButton.getSelection());
174: plugin.setQueryRestartOption(project, m_queryRestartButton
175: .getSelection());
176: }
177:
178: public boolean performOk() {
179: updateProject();
180: return true;
181: }
182: }
|