blob: 841589df0424b456447ec04e543471856f165f1d [file] [log] [blame]
gercanbe0fd052005-11-08 21:47:59 +00001/***************************************************************************************************
2 * Copyright (c) 2005 Eteration A.S. and Gorkem Ercan. All rights reserved. This program and the
3 * accompanying materials are made available under the terms of the Eclipse Public License v1.0
gercan652c9282004-11-07 19:04:18 +00004 * which accompanies this distribution, and is available at
gercanbe0fd052005-11-08 21:47:59 +00005 * http://www.eclipse.org/legal/epl-v10.html
gercan652c9282004-11-07 19:04:18 +00006 *
gercanbe0fd052005-11-08 21:47:59 +00007 * Contributors: Gorkem Ercan - initial API and implementation
8 *
9 **************************************************************************************************/
gercan66440342005-03-08 22:20:47 +000010package org.eclipse.jst.server.generic.ui.internal;
gercan652c9282004-11-07 19:04:18 +000011
gercan652c9282004-11-07 19:04:18 +000012import java.util.Map;
13import org.eclipse.core.runtime.IStatus;
gercand6595ef2004-12-04 15:28:45 +000014import org.eclipse.core.runtime.NullProgressMonitor;
gercan66440342005-03-08 22:20:47 +000015import org.eclipse.jst.server.generic.core.internal.GenericServerRuntime;
ndaid723dcd2004-11-20 21:19:43 +000016import org.eclipse.jst.server.generic.servertype.definition.ServerRuntime;
gercanee6c0132007-11-24 21:44:31 +000017import org.eclipse.osgi.util.NLS;
gercan652c9282004-11-07 19:04:18 +000018import org.eclipse.swt.widgets.Composite;
gercan202cf232004-12-04 11:58:11 +000019import org.eclipse.wst.server.core.IRuntime;
gercan652c9282004-11-07 19:04:18 +000020import org.eclipse.wst.server.core.IRuntimeType;
21import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
gercan652c9282004-11-07 19:04:18 +000022import org.eclipse.wst.server.core.ServerCore;
gercan66440342005-03-08 22:20:47 +000023import org.eclipse.wst.server.core.TaskModel;
gercanefef69d2005-12-03 22:21:20 +000024import org.eclipse.wst.server.core.internal.IInstallableRuntime;
25import org.eclipse.wst.server.core.internal.ServerPlugin;
gercan202cf232004-12-04 11:58:11 +000026import org.eclipse.wst.server.core.model.RuntimeDelegate;
gercan652c9282004-11-07 19:04:18 +000027import org.eclipse.wst.server.ui.wizard.IWizardHandle;
28
29/**
30 * A serverDefinitionType aware wizard for defining runtimes.
31 *
32 * @author Gorkem Ercan
33 */
gercan5dee1ed2006-12-26 17:46:55 +000034public class GenericServerRuntimeWizardFragment extends
35 ServerDefinitionTypeAwareWizardFragment {
36
37 private GenericServerCompositeDecorator[] fDecorators;
38
39 /**
40 * Constructor
41 */
42 public GenericServerRuntimeWizardFragment() {
43 super();
44 }
45
46 /*
47 * (non-Javadoc)
48 *
49 * @see org.eclipse.wst.server.ui.wizard.IWizardFragment#isComplete()
50 */
51 public boolean isComplete() {
52 RuntimeDelegate runtime = getRuntimeDelegate();
53 if( runtime == null )
54 return false;
55 IStatus status = runtime.validate();
56 return (status != null && status.isOK());
57 }
58
59 public void createContent( Composite parent, IWizardHandle handle ) {
60 Map properties = null;
61 ServerRuntime definition = null;
62 if( getRuntimeDelegate() != null )
63 {
64 properties = getRuntimeDelegate().getServerInstanceProperties();
65 definition = getServerTypeDefinition( getServerDefinitionId(),
66 properties );
gercanefef69d2005-12-03 22:21:20 +000067 }
gercan5dee1ed2006-12-26 17:46:55 +000068 IInstallableRuntime ir = ServerPlugin
69 .findInstallableRuntime( getRuntimeDelegate().getRuntime()
70 .getRuntimeType().getId() );
71 if( ir != null )
72 {
73 fDecorators = new GenericServerCompositeDecorator[3];
gercancb4d2fb2007-08-15 10:54:52 +000074 fDecorators[0] = new JRESelectDecorator( getRuntimeDelegate(), getWizard() );
gercan5dee1ed2006-12-26 17:46:55 +000075 fDecorators[1] = new ServerTypeDefinitionRuntimeDecorator(
76 definition, properties, getWizard(), getRuntimeDelegate() );
77 fDecorators[2] = new InstallableRuntimeDecorator( getWizard(),
78 getRuntimeDelegate() );
79 } else
80 {
81 fDecorators = new GenericServerCompositeDecorator[2];
gercancb4d2fb2007-08-15 10:54:52 +000082 fDecorators[0] = new JRESelectDecorator( getRuntimeDelegate(), getWizard() );
gercan5dee1ed2006-12-26 17:46:55 +000083 fDecorators[1] = new ServerTypeDefinitionRuntimeDecorator(
84 definition, properties, getWizard(), getRuntimeDelegate() );
gercanefef69d2005-12-03 22:21:20 +000085 }
gercanf7be76a2005-05-22 22:32:09 +000086
gercan5dee1ed2006-12-26 17:46:55 +000087 new GenericServerComposite( parent, fDecorators );
88 }
gercan80ccf062005-06-07 05:37:59 +000089
gercan5dee1ed2006-12-26 17:46:55 +000090 private String getServerDefinitionId() {
91 String currentDefinition = null;
92 if( getRuntimeDelegate() != null )
93 currentDefinition = getRuntimeDelegate().getRuntime()
94 .getRuntimeType().getId();
95 if( currentDefinition != null && currentDefinition.length() > 0 )
96 {
97 return currentDefinition;
98 }
99 return null;
100 }
gercana14b9c92005-03-07 22:21:24 +0000101
gercan5dee1ed2006-12-26 17:46:55 +0000102 /*
103 * (non-Javadoc)
104 *
105 * @see org.eclipse.wst.server.ui.wizard.IWizardFragment#enter()
106 */
107 public void enter() {
108 if( getRuntimeDelegate() != null )
109 getRuntimeDelegate().getRuntimeWorkingCopy().setName( createName() );
110
111 for( int i = 0; i < fDecorators.length; i++ )
112 {
gercancb4d2fb2007-08-15 10:54:52 +0000113 if( fDecorators[i].validate() )//failed do not continue
gercan5dee1ed2006-12-26 17:46:55 +0000114 return;
115 }
116 }
117
118 public void exit() {
119 // validate to save latest values
120 for( int i = 0; i < fDecorators.length; i++ )
121 {
gercancb4d2fb2007-08-15 10:54:52 +0000122 if( fDecorators[i].validate() )//failed do not continue
gercan5dee1ed2006-12-26 17:46:55 +0000123 return;
124 }
125 }
126
127 private String createName() {
128 RuntimeDelegate dl = getRuntimeDelegate();
129 IRuntimeType runtimeType = dl.getRuntime().getRuntimeType();
gercanee6c0132007-11-24 21:44:31 +0000130 String name = NLS.bind(
gercan5dee1ed2006-12-26 17:46:55 +0000131 GenericServerUIMessages.runtimeName, runtimeType.getName() );
132 IRuntime[] list = ServerCore.getRuntimes();
133 int suffix = 1;
134 String suffixName = name;
135 for( int i = 0; i < list.length; i++ )
136 {
137 if( (list[i].getName().equals( name ) || list[i].getName().equals(
138 suffixName ))
139 && !list[i].equals( dl.getRuntime() ) )
140 suffix++;
141 suffixName = name + ' ' + suffix;
142 }
143
144 if( suffix > 1 )
145 return suffixName;
146 return name;
147 }
148
149 private GenericServerRuntime getRuntimeDelegate() {
150 IRuntimeWorkingCopy wc = (IRuntimeWorkingCopy) getTaskModel()
151 .getObject( TaskModel.TASK_RUNTIME );
152 if( wc == null )
153 return null;
154 return (GenericServerRuntime) wc.loadAdapter(
155 GenericServerRuntime.class, new NullProgressMonitor() );
156 }
157
158 /*
159 * (non-Javadoc)
160 *
gercan2957b582004-11-16 17:20:28 +0000161 * @see org.eclipse.jst.server.generic.internal.ui.ServerDefinitionTypeAwareWizardFragment#description()
162 */
163 public String description() {
gercand2d5c192005-03-16 18:01:19 +0000164 String rName = getRuntimeName();
gercan5dee1ed2006-12-26 17:46:55 +0000165 if( rName == null || rName.length() < 1 )
166 rName = "Generic"; //$NON-NLS-1$
gercanee6c0132007-11-24 21:44:31 +0000167 return NLS.bind(
gercan5dee1ed2006-12-26 17:46:55 +0000168 GenericServerUIMessages.runtimeWizardDescription, rName );
gercan2957b582004-11-16 17:20:28 +0000169 }
gercan5dee1ed2006-12-26 17:46:55 +0000170
171 /*
172 * (non-Javadoc)
173 *
gercan2957b582004-11-16 17:20:28 +0000174 * @see org.eclipse.jst.server.generic.internal.ui.ServerDefinitionTypeAwareWizardFragment#title()
175 */
176 public String title() {
gercand2d5c192005-03-16 18:01:19 +0000177 String rName = getRuntimeName();
gercan5dee1ed2006-12-26 17:46:55 +0000178 if( rName == null || rName.length() < 1 )
179 rName = "Generic"; //$NON-NLS-1$
gercanee6c0132007-11-24 21:44:31 +0000180 return NLS.bind(
gercan5dee1ed2006-12-26 17:46:55 +0000181 GenericServerUIMessages.runtimeWizardTitle, rName );
gercand2d5c192005-03-16 18:01:19 +0000182 }
gercan5dee1ed2006-12-26 17:46:55 +0000183
184 private String getRuntimeName() {
185 if( getRuntimeDelegate() != null
186 && getRuntimeDelegate().getRuntime() != null )
gercand2d5c192005-03-16 18:01:19 +0000187 return getRuntimeDelegate().getRuntime().getName();
188 return null;
gercan2957b582004-11-16 17:20:28 +0000189 }
gercan5dee1ed2006-12-26 17:46:55 +0000190
gercan652c9282004-11-07 19:04:18 +0000191}