blob: d0618975c0a8de204f31f49facc3fe42107b11c5 [file] [log] [blame]
lisaacs78d6d2f2007-02-10 20:47:57 +00001/**********************************************************************
lisaacs6fd080b2008-04-24 01:40:31 +00002 * Copyright (c) 2007, 2008 IBM Corporation and others.
lisaacs78d6d2f2007-02-10 20:47:57 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - Initial API and implementation
10 **********************************************************************/
11package org.eclipse.jst.server.tomcat.ui.internal.editor;
12
13import java.beans.PropertyChangeEvent;
14import java.beans.PropertyChangeListener;
15
16import org.eclipse.core.resources.IWorkspaceRoot;
17import org.eclipse.core.resources.ResourcesPlugin;
18import org.eclipse.core.runtime.IPath;
19import org.eclipse.core.runtime.IStatus;
20import org.eclipse.core.runtime.Path;
21import org.eclipse.core.runtime.Status;
22import org.eclipse.jst.server.tomcat.core.internal.ITomcatServer;
23import org.eclipse.jst.server.tomcat.core.internal.ITomcatServerWorkingCopy;
24import org.eclipse.jst.server.tomcat.core.internal.TomcatServer;
25import org.eclipse.jst.server.tomcat.core.internal.command.SetDeployDirectoryCommand;
26import org.eclipse.jst.server.tomcat.core.internal.command.SetInstanceDirectoryCommand;
27import org.eclipse.jst.server.tomcat.core.internal.command.SetTestEnvironmentCommand;
28import org.eclipse.jst.server.tomcat.ui.internal.ContextIds;
29import org.eclipse.jst.server.tomcat.ui.internal.Messages;
30import org.eclipse.jst.server.tomcat.ui.internal.TomcatUIPlugin;
31import org.eclipse.osgi.util.NLS;
32import org.eclipse.swt.SWT;
33import org.eclipse.swt.events.ModifyEvent;
34import org.eclipse.swt.events.ModifyListener;
35import org.eclipse.swt.events.SelectionAdapter;
36import org.eclipse.swt.events.SelectionEvent;
37import org.eclipse.swt.layout.GridData;
38import org.eclipse.swt.layout.GridLayout;
39import org.eclipse.swt.widgets.Button;
40import org.eclipse.swt.widgets.Composite;
41import org.eclipse.swt.widgets.DirectoryDialog;
42import org.eclipse.swt.widgets.Label;
43import org.eclipse.swt.widgets.Text;
44import org.eclipse.ui.IEditorInput;
45import org.eclipse.ui.IEditorSite;
46import org.eclipse.ui.PlatformUI;
lisaacs98612a42007-02-17 16:31:28 +000047import org.eclipse.ui.forms.IFormColors;
lisaacs78d6d2f2007-02-10 20:47:57 +000048import org.eclipse.ui.forms.events.HyperlinkAdapter;
49import org.eclipse.ui.forms.events.HyperlinkEvent;
50import org.eclipse.ui.forms.widgets.ExpandableComposite;
51import org.eclipse.ui.forms.widgets.FormToolkit;
52import org.eclipse.ui.forms.widgets.Hyperlink;
53import org.eclipse.ui.forms.widgets.Section;
54import org.eclipse.ui.help.IWorkbenchHelpSystem;
55import org.eclipse.wst.server.core.IPublishListener;
56import org.eclipse.wst.server.core.IRuntime;
57import org.eclipse.wst.server.core.IServer;
58import org.eclipse.wst.server.core.util.PublishAdapter;
59import org.eclipse.wst.server.ui.editor.ServerEditorSection;
60/**
61 * Tomcat server general editor page.
62 */
63public class ServerLocationEditorSection extends ServerEditorSection {
64 protected Section section;
65 protected TomcatServer tomcatServer;
66
lisaacs78d6d2f2007-02-10 20:47:57 +000067 protected Hyperlink setDefaultDeployDir;
68
lisaacs78d6d2f2007-02-10 20:47:57 +000069 protected boolean defaultDeployDirIsSet;
70
lisaacs5f5cd562007-03-29 00:27:09 +000071 protected Button serverDirMetadata;
72 protected Button serverDirInstall;
73 protected Button serverDirCustom;
74
lisaacs78d6d2f2007-02-10 20:47:57 +000075 protected Text serverDir;
76 protected Button serverDirBrowse;
77 protected Text deployDir;
78 protected Button deployDirBrowse;
79 protected boolean updating;
80
81 protected PropertyChangeListener listener;
82 protected IPublishListener publishListener;
83 protected IPath workspacePath;
84 protected IPath defaultDeployPath;
85
86 protected boolean allowRestrictedEditing;
87 protected IPath tempDirPath;
lisaacs5f5cd562007-03-29 00:27:09 +000088 protected IPath installDirPath;
lisaacs78d6d2f2007-02-10 20:47:57 +000089
90 // Avoid hardcoding this at some point
91 private final static String METADATADIR = ".metadata";
92 /**
93 * ServerGeneralEditorPart constructor comment.
94 */
95 public ServerLocationEditorSection() {
96 // do nothing
97 }
98
99 /**
100 * Add listeners to detect undo changes and publishing of the server.
101 */
102 protected void addChangeListeners() {
103 listener = new PropertyChangeListener() {
104 public void propertyChange(PropertyChangeEvent event) {
105 if (updating)
106 return;
107 updating = true;
108 if (ITomcatServer.PROPERTY_INSTANCE_DIR.equals(event.getPropertyName())
109 || ITomcatServer.PROPERTY_TEST_ENVIRONMENT.equals(event.getPropertyName())) {
lisaacs5f5cd562007-03-29 00:27:09 +0000110 updateServerDirButtons();
lisaacs78d6d2f2007-02-10 20:47:57 +0000111 updateServerDirFields();
112 validate();
113 }
114 else if (ITomcatServer.PROPERTY_DEPLOY_DIR.equals(event.getPropertyName())) {
115 String s = (String) event.getNewValue();
116 ServerLocationEditorSection.this.deployDir.setText(s);
117 updateDefaultDeployLink();
118 validate();
119 }
120 updating = false;
121 }
122 };
123 server.addPropertyChangeListener(listener);
124
125 publishListener = new PublishAdapter() {
126 public void publishFinished(IServer server2, IStatus status) {
127 boolean flag = false;
128 if (status.isOK() && server2.getModules().length == 0)
129 flag = true;
130 if (flag != allowRestrictedEditing) {
131 allowRestrictedEditing = flag;
132 // Update the state of the fields
133 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
134 public void run() {
lisaacs5f5cd562007-03-29 00:27:09 +0000135 boolean customServerDir = false;
136 if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
137 customServerDir = ServerLocationEditorSection.this.serverDirCustom.getSelection();
138 if (!ServerLocationEditorSection.this.serverDirMetadata.isDisposed())
139 ServerLocationEditorSection.this.serverDirMetadata.setEnabled(allowRestrictedEditing);
140 if (!ServerLocationEditorSection.this.serverDirInstall.isDisposed())
141 ServerLocationEditorSection.this.serverDirInstall.setEnabled(allowRestrictedEditing);
142 if (!ServerLocationEditorSection.this.serverDirCustom.isDisposed())
143 ServerLocationEditorSection.this.serverDirCustom.setEnabled(allowRestrictedEditing);
lisaacs78d6d2f2007-02-10 20:47:57 +0000144 if (!ServerLocationEditorSection.this.serverDir.isDisposed())
lisaacs5f5cd562007-03-29 00:27:09 +0000145 ServerLocationEditorSection.this.serverDir.setEnabled(allowRestrictedEditing && customServerDir);
lisaacs78d6d2f2007-02-10 20:47:57 +0000146 if (!ServerLocationEditorSection.this.serverDirBrowse.isDisposed())
lisaacs5f5cd562007-03-29 00:27:09 +0000147 ServerLocationEditorSection.this.serverDirBrowse.setEnabled(allowRestrictedEditing && customServerDir);
lisaacs78d6d2f2007-02-10 20:47:57 +0000148 if (!ServerLocationEditorSection.this.setDefaultDeployDir.isDisposed())
149 ServerLocationEditorSection.this.setDefaultDeployDir.setEnabled(allowRestrictedEditing);
150 if (!ServerLocationEditorSection.this.deployDir.isDisposed())
151 ServerLocationEditorSection.this.deployDir.setEnabled(allowRestrictedEditing);
152 if (!ServerLocationEditorSection.this.deployDirBrowse.isDisposed())
153 ServerLocationEditorSection.this.deployDirBrowse.setEnabled(allowRestrictedEditing);
154 }
155 });
156 }
157 }
158 };
159 server.getOriginal().addPublishListener(publishListener);
160 }
161
162 /**
163 * Creates the SWT controls for this workbench part.
164 *
165 * @param parent the parent control
166 */
167 public void createSection(Composite parent) {
168 super.createSection(parent);
169 FormToolkit toolkit = getFormToolkit(parent.getDisplay());
170
171 section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED
172 | ExpandableComposite.TITLE_BAR | Section.DESCRIPTION | ExpandableComposite.FOCUS_TITLE);
173 section.setText(Messages.serverEditorLocationsSection);
174 section.setDescription(Messages.serverEditorLocationsDescription);
175 section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
176
177 Composite composite = toolkit.createComposite(section);
178 GridLayout layout = new GridLayout();
179 layout.numColumns = 3;
180 layout.marginHeight = 5;
181 layout.marginWidth = 10;
182 layout.verticalSpacing = 5;
183 layout.horizontalSpacing = 15;
184 composite.setLayout(layout);
185 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
186 IWorkbenchHelpSystem whs = PlatformUI.getWorkbench().getHelpSystem();
187 whs.setHelp(composite, ContextIds.SERVER_EDITOR);
188 whs.setHelp(section, ContextIds.SERVER_EDITOR);
189 toolkit.paintBordersFor(composite);
190 section.setClient(composite);
191
lisaacs5f5cd562007-03-29 00:27:09 +0000192 serverDirMetadata = toolkit.createButton(composite,
193 NLS.bind(Messages.serverEditorServerDirMetadata, Messages.serverEditorDoesNotModify), SWT.RADIO);
194 GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
195 data.horizontalSpan = 3;
196 serverDirMetadata.setLayoutData(data);
197 serverDirMetadata.addSelectionListener(new SelectionAdapter() {
198 public void widgetSelected(SelectionEvent e) {
199 if (updating || !serverDirMetadata.getSelection())
200 return;
lisaacs78d6d2f2007-02-10 20:47:57 +0000201 updating = true;
202 execute(new SetTestEnvironmentCommand(tomcatServer, true));
203 updateServerDirFields();
204 updating = false;
205 validate();
206 }
207 });
lisaacs78d6d2f2007-02-10 20:47:57 +0000208
lisaacs5f5cd562007-03-29 00:27:09 +0000209 serverDirInstall = toolkit.createButton(composite,
210 NLS.bind(Messages.serverEditorServerDirInstall, Messages.serverEditorTakesControl), SWT.RADIO);
211 data = new GridData(SWT.FILL, SWT.CENTER, true, false);
212 data.horizontalSpan = 3;
213 serverDirInstall.setLayoutData(data);
214 serverDirInstall.addSelectionListener(new SelectionAdapter() {
215 public void widgetSelected(SelectionEvent e) {
216 if (updating || !serverDirInstall.getSelection())
217 return;
lisaacs78d6d2f2007-02-10 20:47:57 +0000218 updating = true;
219 execute(new SetTestEnvironmentCommand(tomcatServer, false));
220 updateServerDirFields();
221 updating = false;
222 validate();
223 }
224 });
lisaacs5f5cd562007-03-29 00:27:09 +0000225
226 serverDirCustom = toolkit.createButton(composite,
227 NLS.bind(Messages.serverEditorServerDirCustom, Messages.serverEditorDoesNotModify), SWT.RADIO);
lisaacs78d6d2f2007-02-10 20:47:57 +0000228 data = new GridData(SWT.FILL, SWT.CENTER, true, false);
229 data.horizontalSpan = 3;
lisaacs5f5cd562007-03-29 00:27:09 +0000230 serverDirCustom.setLayoutData(data);
231 serverDirCustom.addSelectionListener(new SelectionAdapter() {
232 public void widgetSelected(SelectionEvent e) {
233 if (updating || !serverDirCustom.getSelection())
234 return;
235 updating = true;
236 execute(new SetTestEnvironmentCommand(tomcatServer, true));
237 updateServerDirFields();
238 updating = false;
239 validate();
240 }
241 });
242
lisaacs78d6d2f2007-02-10 20:47:57 +0000243 // server directory
244 Label label = createLabel(toolkit, composite, Messages.serverEditorServerDir);
245 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
246 label.setLayoutData(data);
247
248 serverDir = toolkit.createText(composite, null, SWT.SINGLE);
249 data = new GridData(SWT.FILL, SWT.CENTER, true, false);
deboer58ed6862008-03-24 22:53:42 +0000250 data.widthHint = 75;
lisaacs78d6d2f2007-02-10 20:47:57 +0000251 serverDir.setLayoutData(data);
252 serverDir.addModifyListener(new ModifyListener() {
253 public void modifyText(ModifyEvent e) {
254 if (updating)
255 return;
256 updating = true;
257 execute(new SetInstanceDirectoryCommand(tomcatServer, getServerDir()));
258 updating = false;
259 validate();
260 }
261 });
262
263 serverDirBrowse = toolkit.createButton(composite, Messages.editorBrowse, SWT.PUSH);
264 serverDirBrowse.addSelectionListener(new SelectionAdapter() {
265 public void widgetSelected(SelectionEvent se) {
266 DirectoryDialog dialog = new DirectoryDialog(serverDir.getShell());
267 dialog.setMessage(Messages.serverEditorBrowseDeployMessage);
268 dialog.setFilterPath(serverDir.getText());
269 String selectedDirectory = dialog.open();
270 if (selectedDirectory != null && !selectedDirectory.equals(serverDir.getText())) {
271 updating = true;
lisaacs98612a42007-02-17 16:31:28 +0000272 // Make relative if relative to the workspace
273 IPath path = new Path(selectedDirectory);
274 if (workspacePath.isPrefixOf(path)) {
275 int cnt = path.matchingFirstSegments(workspacePath);
276 path = path.removeFirstSegments(cnt).setDevice(null);
277 selectedDirectory = path.toOSString();
278 }
lisaacs78d6d2f2007-02-10 20:47:57 +0000279 execute(new SetInstanceDirectoryCommand(tomcatServer, selectedDirectory));
lisaacs5f5cd562007-03-29 00:27:09 +0000280 updateServerDirButtons();
lisaacs98612a42007-02-17 16:31:28 +0000281 updateServerDirFields();
lisaacs78d6d2f2007-02-10 20:47:57 +0000282 updating = false;
283 validate();
284 }
285 }
286 });
287 serverDirBrowse.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
288
289 // deployment directory link
290 setDefaultDeployDir = toolkit.createHyperlink(composite,
291 NLS.bind(Messages.serverEditorSetDefaultDeployDirLink, ""), SWT.WRAP);
292 setDefaultDeployDir.addHyperlinkListener(new HyperlinkAdapter() {
293 public void linkActivated(HyperlinkEvent e) {
294 updating = true;
295 execute(new SetDeployDirectoryCommand(tomcatServer, ITomcatServerWorkingCopy.DEFAULT_DEPLOYDIR));
lisaacs98612a42007-02-17 16:31:28 +0000296 deployDir.setText(ITomcatServerWorkingCopy.DEFAULT_DEPLOYDIR);
297 updateDefaultDeployLink();
lisaacs78d6d2f2007-02-10 20:47:57 +0000298 updating = false;
299 validate();
300 }
301 });
302 data = new GridData(SWT.FILL, SWT.CENTER, true, false);
303 data.horizontalSpan = 3;
304 setDefaultDeployDir.setLayoutData(data);
305
306 // deployment directory
307 label = createLabel(toolkit, composite, Messages.serverEditorDeployDir);
308 data = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
309 label.setLayoutData(data);
310
311 deployDir = toolkit.createText(composite, null);
312 data = new GridData(SWT.FILL, SWT.CENTER, true, false);
313 deployDir.setLayoutData(data);
314 deployDir.addModifyListener(new ModifyListener() {
315 public void modifyText(ModifyEvent e) {
316 if (updating)
317 return;
318 updating = true;
319 execute(new SetDeployDirectoryCommand(tomcatServer, deployDir.getText().trim()));
320 updateDefaultDeployLink();
321 updating = false;
322 validate();
323 }
324 });
325
326 deployDirBrowse = toolkit.createButton(composite, Messages.editorBrowse, SWT.PUSH);
327 deployDirBrowse.addSelectionListener(new SelectionAdapter() {
328 public void widgetSelected(SelectionEvent se) {
329 DirectoryDialog dialog = new DirectoryDialog(deployDir.getShell());
330 dialog.setMessage(Messages.serverEditorBrowseDeployMessage);
331 dialog.setFilterPath(deployDir.getText());
332 String selectedDirectory = dialog.open();
333 if (selectedDirectory != null && !selectedDirectory.equals(deployDir.getText())) {
334 updating = true;
335 execute(new SetDeployDirectoryCommand(tomcatServer, selectedDirectory));
336 deployDir.setText(selectedDirectory);
337 updating = false;
338 validate();
339 }
340 }
341 });
342 deployDirBrowse.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
343
344 initialize();
345 }
346
347 protected Label createLabel(FormToolkit toolkit, Composite parent, String text) {
348 Label label = toolkit.createLabel(parent, text);
lisaacs98612a42007-02-17 16:31:28 +0000349 label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
lisaacs78d6d2f2007-02-10 20:47:57 +0000350 return label;
351 }
352
353 /**
354 * @see ServerEditorSection#dispose()
355 */
356 public void dispose() {
357 if (server != null) {
358 server.removePropertyChangeListener(listener);
359 if (server.getOriginal() != null)
360 server.getOriginal().removePublishListener(publishListener);
361 }
362 }
363
364 /**
365 * @see ServerEditorSection#init(IEditorSite, IEditorInput)
366 */
367 public void init(IEditorSite site, IEditorInput input) {
368 super.init(site, input);
369
370 // Cache workspace and default deploy paths
371 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
372 workspacePath = root.getLocation();
373 defaultDeployPath = new Path(ITomcatServerWorkingCopy.DEFAULT_DEPLOYDIR);
374
375 if (server != null) {
376 tomcatServer = (TomcatServer) server.loadAdapter(TomcatServer.class, null);
377 addChangeListeners();
378 }
379 initialize();
380 }
381
382 /**
383 * Initialize the fields in this editor.
384 */
385 protected void initialize() {
386 if (serverDir== null || tomcatServer == null)
387 return;
388 updating = true;
389
390 IRuntime runtime = server.getRuntime();
391 // If not Tomcat 3.2, update description to mention catalina.base
392 if (runtime != null && runtime.getRuntimeType().getId().indexOf("32") < 0)
393 section.setDescription(Messages.serverEditorLocationsDescription2);
deboeree724c62007-07-12 21:20:59 +0000394 if (runtime != null)
395 installDirPath = runtime.getLocation();
lisaacs5f5cd562007-03-29 00:27:09 +0000396
lisaacs78d6d2f2007-02-10 20:47:57 +0000397 // determine if editing of locations is allowed
398 allowRestrictedEditing = false;
399 IPath basePath = tomcatServer.getRuntimeBaseDirectory();
400 if (!readOnly) {
401 // If server has not been published, or server is published with no modules, allow editing
402 // TODO Find better way to determine if server hasn't been published
403 if ((basePath != null && !basePath.append("conf").toFile().exists())
404 || (server.getOriginal().getServerPublishState() == IServer.PUBLISH_STATE_NONE
405 && server.getOriginal().getModules().length == 0)) {
406 allowRestrictedEditing = true;
407 }
408 }
lisaacs5f5cd562007-03-29 00:27:09 +0000409
lisaacs78d6d2f2007-02-10 20:47:57 +0000410 // Update server related fields
lisaacs5f5cd562007-03-29 00:27:09 +0000411 updateServerDirButtons();
lisaacs78d6d2f2007-02-10 20:47:57 +0000412 updateServerDirFields();
413
lisaacs5f5cd562007-03-29 00:27:09 +0000414 serverDirMetadata.setEnabled(allowRestrictedEditing);
415 serverDirInstall.setEnabled(allowRestrictedEditing);
416 serverDirCustom.setEnabled(allowRestrictedEditing);
lisaacs78d6d2f2007-02-10 20:47:57 +0000417
418 // Update deployment related fields
419 updateDefaultDeployLink();
420
421 deployDir.setText(tomcatServer.getDeployDirectory());
422
423 setDefaultDeployDir.setEnabled(allowRestrictedEditing);
424 deployDir.setEnabled(allowRestrictedEditing);
425 deployDirBrowse.setEnabled(allowRestrictedEditing);
426
427 updating = false;
428 validate();
429 }
430
431 protected String getServerDir() {
432 String dir = null;
433 if (serverDir != null) {
434 dir = serverDir.getText().trim();
435 IPath path = new Path(dir);
436 // Adjust if the temp dir is known and has been entered
437 if (tempDirPath != null && tempDirPath.equals(path))
438 dir = null;
439 // If under the workspace, make relative
440 else if (workspacePath.isPrefixOf(path)) {
441 int cnt = path.matchingFirstSegments(workspacePath);
lisaacs98612a42007-02-17 16:31:28 +0000442 path = path.removeFirstSegments(cnt).setDevice(null);
lisaacs78d6d2f2007-02-10 20:47:57 +0000443 dir = path.toOSString();
444 }
445 }
446 return dir;
447 }
448
lisaacs5f5cd562007-03-29 00:27:09 +0000449 protected void updateServerDirButtons() {
450 if (tomcatServer.getInstanceDirectory() == null) {
451 IPath path = tomcatServer.getRuntimeBaseDirectory();
deboer5bfbcee2008-06-20 15:08:43 +0000452 if (path != null && path.equals(installDirPath)) {
lisaacs5f5cd562007-03-29 00:27:09 +0000453 serverDirInstall.setSelection(true);
454 serverDirMetadata.setSelection(false);
455 serverDirCustom.setSelection(false);
deboer5bfbcee2008-06-20 15:08:43 +0000456 } else {
lisaacs5f5cd562007-03-29 00:27:09 +0000457 serverDirMetadata.setSelection(true);
458 serverDirInstall.setSelection(false);
459 serverDirCustom.setSelection(false);
460 }
deboer5bfbcee2008-06-20 15:08:43 +0000461 } else {
lisaacs5f5cd562007-03-29 00:27:09 +0000462 serverDirCustom.setSelection(true);
463 serverDirMetadata.setSelection(false);
464 serverDirInstall.setSelection(false);
465 }
lisaacs78d6d2f2007-02-10 20:47:57 +0000466 }
467
lisaacs5f5cd562007-03-29 00:27:09 +0000468 protected void updateServerDirFields() {
469 updateServerDir();
470 boolean customServerDir = serverDirCustom.getSelection();
471 serverDir.setEnabled(allowRestrictedEditing && customServerDir);
472 serverDirBrowse.setEnabled(allowRestrictedEditing && customServerDir);
lisaacs78d6d2f2007-02-10 20:47:57 +0000473 }
lisaacs5f5cd562007-03-29 00:27:09 +0000474
lisaacs78d6d2f2007-02-10 20:47:57 +0000475 protected void updateServerDir() {
476 IPath path = tomcatServer.getRuntimeBaseDirectory();
deboer5bfbcee2008-06-20 15:08:43 +0000477 if (path == null)
478 serverDir.setText("");
479 else if (workspacePath.isPrefixOf(path)) {
lisaacs78d6d2f2007-02-10 20:47:57 +0000480 int cnt = path.matchingFirstSegments(workspacePath);
lisaacs98612a42007-02-17 16:31:28 +0000481 path = path.removeFirstSegments(cnt).setDevice(null);
lisaacs78d6d2f2007-02-10 20:47:57 +0000482 serverDir.setText(path.toOSString());
483 // cache the relative temp dir path if that is what we have
484 if (tempDirPath == null) {
485 if (tomcatServer.isTestEnvironment() && tomcatServer.getInstanceDirectory() == null)
486 tempDirPath = path;
487 }
deboer5bfbcee2008-06-20 15:08:43 +0000488 } else
lisaacs78d6d2f2007-02-10 20:47:57 +0000489 serverDir.setText(path.toOSString());
490 }
491
492 protected void updateDefaultDeployLink() {
493 boolean newState = defaultDeployPath.equals(new Path(tomcatServer.getDeployDirectory()));
494 if (newState != defaultDeployDirIsSet) {
495 setDefaultDeployDir.setText(
496 newState ? Messages.serverEditorSetDefaultDeployDirLink2
497 : Messages.serverEditorSetDefaultDeployDirLink);
498 defaultDeployDirIsSet = newState;
499 }
500 }
501
502 /**
503 * @see ServerEditorSection#getSaveStatus()
504 */
505 public IStatus[] getSaveStatus() {
506 if (tomcatServer != null) {
507 // Check the instance directory
508 String dir = tomcatServer.getInstanceDirectory();
509 if (dir != null) {
510 IPath path = new Path(dir);
511 // Must not be the same as the workspace location
512 if (dir.length() == 0 || workspacePath.equals(path)) {
513 return new IStatus [] {
514 new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID, Messages.errorServerDirIsRoot)};
515 }
516 // User specified value may not be under the ".metadata" folder of the workspace
517 else if (workspacePath.isPrefixOf(path)
518 || (!path.isAbsolute() && METADATADIR.equals(path.segment(0)))) {
519 int cnt = path.matchingFirstSegments(workspacePath);
520 if (METADATADIR.equals(path.segment(cnt))) {
521 return new IStatus [] {
522 new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID, NLS.bind(Messages.errorServerDirUnderRoot, METADATADIR))};
523 }
524 }
lisaacs63f67d22008-04-23 18:53:47 +0000525 else if (path.equals(installDirPath))
lisaacs5f5cd562007-03-29 00:27:09 +0000526 return new IStatus [] {
527 new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID,
528 NLS.bind(Messages.errorServerDirCustomNotInstall,
529 NLS.bind(Messages.serverEditorServerDirInstall, "").trim()))};
530 }
531 else {
532 IPath path = tomcatServer.getRuntimeBaseDirectory();
533 // If non-custom instance dir is not the install and metadata isn't the selection, return error
534 if (!path.equals(installDirPath) && !serverDirMetadata.getSelection()) {
535 return new IStatus [] {
536 new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID,
537 NLS.bind(Messages.errorServerDirCustomNotMetadata,
538 NLS.bind(Messages.serverEditorServerDirMetadata, "").trim()))};
539 }
lisaacs78d6d2f2007-02-10 20:47:57 +0000540 }
541
542 // Check the deployment directory
543 dir = tomcatServer.getDeployDirectory();
544 // Deploy directory must be set
545 if (dir == null || dir.length() == 0) {
546 return new IStatus [] {
547 new Status(IStatus.ERROR, TomcatUIPlugin.PLUGIN_ID, Messages.errorDeployDirNotSpecified)};
548 }
549 }
550 // use default implementation to return success
551 return super.getSaveStatus();
552 }
553
554 protected void validate() {
555 if (tomcatServer != null) {
556 // Validate instance directory
557 String dir = tomcatServer.getInstanceDirectory();
558 if (dir != null) {
559 IPath path = new Path(dir);
560 // Must not be the same as the workspace location
561 if (dir.length() == 0 || workspacePath.equals(path)) {
562 setErrorMessage(Messages.errorServerDirIsRoot);
563 return;
564 }
565 // User specified value may not be under the ".metadata" folder of the workspace
566 else if (workspacePath.isPrefixOf(path)
567 || (!path.isAbsolute() && METADATADIR.equals(path.segment(0)))) {
568 int cnt = path.matchingFirstSegments(workspacePath);
569 if (METADATADIR.equals(path.segment(cnt))) {
570 setErrorMessage(NLS.bind(Messages.errorServerDirUnderRoot, METADATADIR));
571 return;
572 }
573 }
lisaacs63f67d22008-04-23 18:53:47 +0000574 else if (path.equals(installDirPath)) {
lisaacs5f5cd562007-03-29 00:27:09 +0000575 setErrorMessage(NLS.bind(Messages.errorServerDirCustomNotInstall,
576 NLS.bind(Messages.serverEditorServerDirInstall, "").trim()));
577 return;
578 }
579 }
580 else {
581 IPath path = tomcatServer.getRuntimeBaseDirectory();
582 // If non-custom instance dir is not the install and metadata isn't the selection, return error
deboer5bfbcee2008-06-20 15:08:43 +0000583 if (path != null && !path.equals(installDirPath) && !serverDirMetadata.getSelection()) {
lisaacs5f5cd562007-03-29 00:27:09 +0000584 setErrorMessage(NLS.bind(Messages.errorServerDirCustomNotMetadata,
585 NLS.bind(Messages.serverEditorServerDirMetadata, "").trim()));
586 }
lisaacs78d6d2f2007-02-10 20:47:57 +0000587 }
588
589 // Check the deployment directory
590 dir = tomcatServer.getDeployDirectory();
591 // Deploy directory must be set
592 if (dir == null || dir.length() == 0) {
593 setErrorMessage(Messages.errorDeployDirNotSpecified);
594 return;
595 }
596 }
597 // All is okay, clear any previous error
598 setErrorMessage(null);
599 }
600}