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.wizards;
006:
007: import org.eclipse.core.resources.IProject;
008: import org.eclipse.jdt.core.IJavaProject;
009: import org.eclipse.jface.wizard.WizardPage;
010: import org.eclipse.swt.SWT;
011: import org.eclipse.swt.events.SelectionAdapter;
012: import org.eclipse.swt.events.SelectionEvent;
013: import org.eclipse.swt.layout.GridData;
014: import org.eclipse.swt.layout.GridLayout;
015: import org.eclipse.swt.widgets.Button;
016: import org.eclipse.swt.widgets.Composite;
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 class SetupWizardPage extends WizardPage {
029: private IProject m_project;
030: private Text m_configPathField;
031: private Button m_configFileButton;
032: private Text m_serverOptionsField;
033: private Button m_resetOptionsButton;
034:
035: private static final String TERRACOTTA_CONFIG = "Terracotta Configuration";
036: private static final String BROWSE = "Browse...";
037: private static final String RESET = "Reset";
038: private static final String SERVER_OPTIONS = "Server Options";
039: private static final String PAGE_NAME = "TCSetupWizardPage";
040: private static final String PAGE_TITLE = "Terracotta Project Setup";
041: private static final String PAGE_DESC = "Specify the location of your Terracotta configuration file and\n"
042: + "Terracotta server Java runtime options";
043:
044: private static final String DEFAULT_CONFIG_FILENAME = TcPlugin.DEFAULT_CONFIG_FILENAME;
045: private static final String DEFAULT_SERVER_OPTIONS = TcPlugin.DEFAULT_SERVER_OPTIONS;
046:
047: public SetupWizardPage(IJavaProject project) {
048: super (PAGE_NAME);
049:
050: m_project = project.getProject();
051:
052: setTitle(PAGE_TITLE);
053: setDescription(PAGE_DESC);
054: }
055:
056: public void createControl(Composite parent) {
057: final Composite topComp = new Composite(parent, SWT.NONE);
058: GridLayout gridLayout = new GridLayout();
059: gridLayout.numColumns = 1;
060: gridLayout.makeColumnsEqualWidth = false;
061: topComp.setLayout(gridLayout);
062: topComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
063:
064: Group domainConfig = new Group(topComp, SWT.SHADOW_ETCHED_IN);
065: domainConfig.setText(TERRACOTTA_CONFIG);
066: gridLayout = new GridLayout();
067: gridLayout.numColumns = 2;
068: domainConfig.setLayout(gridLayout);
069: domainConfig.setLayoutData(new GridData(
070: GridData.FILL_HORIZONTAL));
071:
072: m_configPathField = new Text(domainConfig, SWT.SINGLE
073: | SWT.BORDER);
074: m_configPathField.setLayoutData(new GridData(
075: GridData.FILL_HORIZONTAL));
076: m_configPathField.setText(DEFAULT_CONFIG_FILENAME);
077:
078: m_configFileButton = new Button(domainConfig, SWT.PUSH);
079: m_configFileButton.setText(BROWSE);
080: m_configFileButton.setLayoutData(new GridData(
081: GridData.HORIZONTAL_ALIGN_END));
082: SWTUtil.applyDefaultButtonSize(m_configFileButton);
083: m_configFileButton.addSelectionListener(new SelectionAdapter() {
084: public void widgetSelected(SelectionEvent e) {
085: NavigatorBehavior behavior = new ConfigFileBehavior();
086: PackageNavigator dialog = new PackageNavigator(
087: getShell(), behavior.getTitle(), m_project,
088: behavior);
089: dialog.addValueListener(new UpdateEventListener() {
090: public void handleUpdate(UpdateEvent event) {
091: m_configPathField.setText((String) event.data);
092: }
093: });
094: dialog.open();
095: }
096: });
097: Group serverOptions = new Group(topComp, SWT.SHADOW_ETCHED_IN);
098: serverOptions.setText(SERVER_OPTIONS);
099: gridLayout = new GridLayout();
100: gridLayout.numColumns = 2;
101: serverOptions.setLayout(gridLayout);
102: GridData gridData = new GridData();
103: gridData.horizontalAlignment = GridData.FILL;
104: gridData.heightHint = 60;
105: serverOptions.setLayoutData(gridData);
106:
107: m_serverOptionsField = new Text(serverOptions, SWT.MULTI
108: | SWT.BORDER | SWT.V_SCROLL);
109: GridData gd = new GridData(GridData.FILL_BOTH);
110: m_serverOptionsField.setLayoutData(gd);
111: m_serverOptionsField.setText(DEFAULT_SERVER_OPTIONS);
112:
113: m_resetOptionsButton = new Button(serverOptions, SWT.PUSH);
114: m_resetOptionsButton.setText(RESET);
115: SWTUtil.applyDefaultButtonSize(m_resetOptionsButton);
116: gridData = (GridData) m_resetOptionsButton.getLayoutData();
117: gridData.verticalAlignment = SWT.BEGINNING;
118: m_resetOptionsButton
119: .addSelectionListener(new SelectionAdapter() {
120: public void widgetSelected(SelectionEvent e) {
121: m_serverOptionsField
122: .setText(DEFAULT_SERVER_OPTIONS);
123: }
124: });
125: setControl(topComp);
126: }
127:
128: public boolean isPageComplete() {
129: return true;
130: }
131:
132: public boolean canFinish() {
133: return isPageComplete();
134: }
135:
136: public String getDomainConfigurationPath() {
137: return m_configPathField.getText();
138: }
139:
140: public String getServerOptions() {
141: return m_serverOptionsField.getText();
142: }
143: }
|