001: /*
002:
003: Derby - Class org.apache.derby.ui.properties.DerbyPropertiesPage
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.ui.properties;
023:
024: import org.apache.derby.ui.common.CommonNames;
025: import org.apache.derby.ui.common.Messages;
026: import org.apache.derby.ui.util.DerbyServerUtils;
027: import org.apache.derby.ui.util.Logger;
028: import org.apache.derby.ui.util.SelectionUtil;
029: import org.eclipse.core.resources.IProject;
030: import org.eclipse.core.runtime.CoreException;
031: import org.eclipse.core.runtime.IStatus;
032: import org.eclipse.jface.dialogs.MessageDialog;
033: import org.eclipse.swt.SWT;
034: import org.eclipse.swt.graphics.Color;
035: import org.eclipse.swt.layout.GridData;
036: import org.eclipse.swt.layout.GridLayout;
037: import org.eclipse.swt.widgets.Composite;
038: import org.eclipse.swt.widgets.Control;
039: import org.eclipse.swt.widgets.Label;
040: import org.eclipse.swt.widgets.Shell;
041: import org.eclipse.swt.widgets.Text;
042: import org.eclipse.ui.dialogs.PropertyPage;
043:
044: public class DerbyPropertiesPage extends PropertyPage {
045: public DerbyPropertiesPage() {
046: super ();
047: }
048:
049: protected DerbyProperties dsProps;
050: protected Text hostText;
051: protected Text portText;
052: protected Text systemHomeText;
053: private boolean isServerRunning;
054:
055: protected void addControls(Composite parent) {
056: Composite composite = createDefaultComposite(parent);
057:
058: //Network Server Settings
059: Label txt = new Label(composite, SWT.NONE);
060: txt.setBackground(new Color(null, 0, 0, 0));
061: txt.setForeground(new Color(null, 255, 255, 255));
062: txt.setText("Network Server Settings:");
063:
064: //separator
065: Label separatorLabel = new Label(composite, SWT.SEPARATOR
066: | SWT.HORIZONTAL);
067: separatorLabel.setLayoutData(getSeperatorLabelGridData());
068:
069: org.eclipse.swt.widgets.Label portLabel = new Label(composite,
070: SWT.NONE);
071: portLabel.setText("&Network Server Port:");
072: portText = new Text(composite, SWT.SINGLE | SWT.BORDER);
073: GridData gd = new GridData();
074: gd.widthHint = convertWidthInCharsToPixels(6);
075: portText.setLayoutData(gd);
076:
077: Label hostLabel = new Label(composite, SWT.NONE);
078: hostLabel.setText("&Network Server Host:");
079: hostText = new Text(composite, SWT.SINGLE | SWT.BORDER);
080: gd = new GridData();
081: gd.widthHint = convertWidthInCharsToPixels(16);
082: hostText.setLayoutData(gd);
083:
084: //Derby System Properties
085: separatorLabel = new Label(composite, SWT.NONE);
086: separatorLabel.setLayoutData(getSeperatorLabelGridData());
087: separatorLabel.setText("");
088:
089: Label txt1 = new Label(composite, SWT.NONE);
090: txt1.setBackground(new Color(null, 0, 0, 0));
091: txt1.setForeground(new Color(null, 255, 255, 255));
092: txt1.setText("Derby System Properties:");
093:
094: //separator
095: separatorLabel = new Label(composite, SWT.SEPARATOR
096: | SWT.HORIZONTAL);
097: separatorLabel.setLayoutData(getSeperatorLabelGridData());
098:
099: Label sytemHomeLabel = new Label(composite, SWT.NONE);
100: sytemHomeLabel.setText("&derby.system.home=");
101: systemHomeText = new Text(composite, SWT.SINGLE | SWT.BORDER);
102: gd = new GridData();
103: gd.widthHint = convertWidthInCharsToPixels(16);
104: systemHomeText.setLayoutData(gd);
105: }
106:
107: protected Composite createDefaultComposite(Composite parent) {
108: Composite composite = new Composite(parent, SWT.NULL);
109: GridLayout layout = new GridLayout();
110: layout.numColumns = 2;
111: composite.setLayout(layout);
112:
113: GridData data = new GridData();
114: data.verticalAlignment = GridData.FILL;
115: data.horizontalAlignment = GridData.FILL;
116: composite.setLayoutData(data);
117:
118: return composite;
119: }
120:
121: protected void fillControls() {
122: portText.setText(Integer.toString(dsProps.getPort()));
123: hostText.setText(dsProps.getHost());
124: systemHomeText.setText(dsProps.getSystemHome());
125: isServerRunning = checkServer();
126: // if the server is running do not allow
127: // editing of the settings
128: if (isServerRunning) {
129: portText.setEditable(false);
130: hostText.setEditable(false);
131: systemHomeText.setEditable(false);
132: }
133: }
134:
135: protected boolean checkServer() {
136: IProject proj = (IProject) getElement();
137: boolean serverRunning = false;
138: try {
139: serverRunning = DerbyServerUtils.getDefault().getRunning(
140: proj);
141: } catch (CoreException ce) {
142: Logger.log(SelectionUtil.getStatusMessages(ce),
143: IStatus.ERROR);
144: }
145: return serverRunning;
146: }
147:
148: protected void getParams() {
149: dsProps = new DerbyProperties();
150: try {
151: dsProps.setPort(Integer.parseInt(portText.getText()));
152: } catch (NumberFormatException ne) {
153: // do nothing; use the default port number
154: }
155: dsProps.setHost(hostText.getText());
156: dsProps.setSystemHome(systemHomeText.getText());
157:
158: // if the server is running inform the user
159: // to stop the server before changing the settings
160: if (isServerRunning) {
161: Shell shell = new Shell();
162: MessageDialog.openInformation(shell,
163: CommonNames.PLUGIN_NAME, Messages.SERVER_RUNNING);
164: }
165: }
166:
167: protected GridData getSeperatorLabelGridData() {
168:
169: GridData gridData = new GridData(GridData.BEGINNING
170: | GridData.HORIZONTAL_ALIGN_FILL
171: | GridData.GRAB_VERTICAL | GridData.BEGINNING
172: | GridData.VERTICAL_ALIGN_BEGINNING
173: | GridData.VERTICAL_ALIGN_FILL);
174: gridData.horizontalSpan = 2;
175: gridData.grabExcessVerticalSpace = false;
176: gridData.grabExcessHorizontalSpace = true;
177: return gridData;
178:
179: }
180:
181: protected void performDefaults() {
182: dsProps = new DerbyProperties();
183: fillControls();
184: }
185:
186: public boolean performOk() {
187: IProject proj = (IProject) getElement();
188: getParams();
189: try {
190:
191: dsProps.save(proj.getProject());
192: } catch (CoreException ce) {
193: System.err.println(SelectionUtil.getStatusMessages(ce));
194: return false;
195: }
196: return true;
197: }
198:
199: protected Control createContents(Composite parent) {
200: Composite composite = new Composite(parent, SWT.NONE);
201: GridLayout layout = new GridLayout();
202: composite.setLayout(layout);
203: GridData data = new GridData(GridData.FILL);
204: data.grabExcessHorizontalSpace = true;
205: composite.setLayoutData(data);
206: addControls(composite);
207: IProject proj = (IProject) getElement();
208: try {
209: dsProps = new DerbyProperties(proj);
210: fillControls();
211: } catch (CoreException ce) {
212: Logger.log(SelectionUtil.getStatusMessages(ce),
213: IStatus.ERROR);
214: }
215: return composite;
216: }
217:
218: }
|