blob: 298ac6488b32d2be5dabfe12f6f24360f867dfa8 [file] [log] [blame]
gercan652c9282004-11-07 19:04:18 +00001/*******************************************************************************
2 * Copyright (c) 2004 Eteration Bilisim A.S.
3 * All rights reserved.   This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
7 *
8 * Contributors:
9 * Gorkem Ercan - initial API and implementation
10 * Naci M. Dai
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
16 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
22 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 * ====================================================================
25 *
26 * This software consists of voluntary contributions made by many
27 * individuals on behalf of the Eteration Bilisim A.S. For more
28 * information on eteration, please see
29 * <http://www.eteration.com/>.
30 ***************************************************************************/
gercan66440342005-03-08 22:20:47 +000031package org.eclipse.jst.server.generic.ui.internal;
gercan652c9282004-11-07 19:04:18 +000032
gercan652c9282004-11-07 19:04:18 +000033import java.util.Map;
34import org.eclipse.core.runtime.IStatus;
gercand6595ef2004-12-04 15:28:45 +000035import org.eclipse.core.runtime.NullProgressMonitor;
gercan66440342005-03-08 22:20:47 +000036import org.eclipse.jst.server.generic.core.internal.GenericServerRuntime;
ndaid723dcd2004-11-20 21:19:43 +000037import org.eclipse.jst.server.generic.servertype.definition.ServerRuntime;
gercan652c9282004-11-07 19:04:18 +000038import org.eclipse.swt.widgets.Composite;
gercan202cf232004-12-04 11:58:11 +000039import org.eclipse.wst.server.core.IRuntime;
gercan652c9282004-11-07 19:04:18 +000040import org.eclipse.wst.server.core.IRuntimeType;
41import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
gercan652c9282004-11-07 19:04:18 +000042import org.eclipse.wst.server.core.ServerCore;
gercan66440342005-03-08 22:20:47 +000043import org.eclipse.wst.server.core.TaskModel;
gercan202cf232004-12-04 11:58:11 +000044import org.eclipse.wst.server.core.model.RuntimeDelegate;
gercan652c9282004-11-07 19:04:18 +000045import org.eclipse.wst.server.ui.wizard.IWizardHandle;
46
47/**
48 * A serverDefinitionType aware wizard for defining runtimes.
49 *
50 * @author Gorkem Ercan
51 */
52public class GenericServerRuntimeWizardFragment extends ServerDefinitionTypeAwareWizardFragment {
53
gercan53c00bb2005-05-18 19:54:52 +000054 private GenericServerRuntime fRuntimeDelegate;
gercanf7be76a2005-05-22 22:32:09 +000055 private GenericServerCompositeDecorator[] fDecorators;
gercan652c9282004-11-07 19:04:18 +000056
57 /**
58 * Constructor
59 */
60 public GenericServerRuntimeWizardFragment() {
61 super();
62 }
63 /* (non-Javadoc)
gercand2d5c192005-03-16 18:01:19 +000064 * @see org.eclipse.wst.server.ui.wizard.IWizardFragment#isComplete()
gercan652c9282004-11-07 19:04:18 +000065 */
66 public boolean isComplete() {
gercan202cf232004-12-04 11:58:11 +000067 RuntimeDelegate runtime = getRuntimeDelegate();
gercan652c9282004-11-07 19:04:18 +000068 if (runtime == null)
69 return false;
70 IStatus status = runtime.validate();
71 return (status != null && status.isOK());
72 }
73
74 public void createContent(Composite parent, IWizardHandle handle) {
gercan652c9282004-11-07 19:04:18 +000075 Map properties= null;
gercan985a66b2005-04-23 06:25:45 +000076 ServerRuntime definition=null;
gercanf747ac02005-06-05 21:51:55 +000077 if(getRuntimeDelegate()!=null){
78 properties = getRuntimeDelegate().getServerInstanceProperties();
gercan985a66b2005-04-23 06:25:45 +000079 definition = getServerTypeDefinition(getServerDefinitionId(),properties);
80 }
gercanf747ac02005-06-05 21:51:55 +000081 fDecorators= new GenericServerCompositeDecorator[2];
gercanf60c5c32005-05-24 20:35:45 +000082 fDecorators[0]= new JRESelectDecorator(getRuntimeDelegate());
83 fDecorators[1]= new ServerTypeDefinitionRuntimeDecorator(definition,properties,getWizard(),getRuntimeDelegate());
gercanf7be76a2005-05-22 22:32:09 +000084 GenericServerComposite composite = new GenericServerComposite(parent,fDecorators);
gercanf747ac02005-06-05 21:51:55 +000085
gercanf7be76a2005-05-22 22:32:09 +000086 }
87
gercan652c9282004-11-07 19:04:18 +000088
gercanf7be76a2005-05-22 22:32:09 +000089 private String getServerDefinitionId(){
gercan652c9282004-11-07 19:04:18 +000090 String currentDefinition= null;
gercan202cf232004-12-04 11:58:11 +000091 if(getRuntimeDelegate()!=null)
gercand2d5c192005-03-16 18:01:19 +000092 currentDefinition = getRuntimeDelegate().getRuntime().getRuntimeType().getId();
gercan652c9282004-11-07 19:04:18 +000093 if(currentDefinition!= null && currentDefinition.length()>0)
94 {
95 return currentDefinition;
96 }
97 return null;
98 }
99
gercan652c9282004-11-07 19:04:18 +0000100
101
102 /* (non-Javadoc)
103 * @see org.eclipse.wst.server.ui.wizard.IWizardFragment#enter()
104 */
105 public void enter() {
gercanf747ac02005-06-05 21:51:55 +0000106 if(getRuntimeDelegate()!=null)
107 getRuntimeDelegate().getRuntimeWorkingCopy().setName(createName());
gercanf7be76a2005-05-22 22:32:09 +0000108 for (int i = 0; i < fDecorators.length; i++) {
109 if(fDecorators[i].validate())
110 return;
gercan652c9282004-11-07 19:04:18 +0000111 }
112 }
113
gercan80ccf062005-06-07 05:37:59 +0000114
gercana14b9c92005-03-07 22:21:24 +0000115
gercan652c9282004-11-07 19:04:18 +0000116 private String createName()
117 {
gercan202cf232004-12-04 11:58:11 +0000118 RuntimeDelegate dl = getRuntimeDelegate();
119 IRuntimeType runtimeType = dl.getRuntime().getRuntimeType();
gercand04ac652005-05-25 20:06:30 +0000120 String name = GenericServerUIMessages.bind(GenericServerUIMessages.runtimeName,runtimeType.getName());
gercan202cf232004-12-04 11:58:11 +0000121 IRuntime[] list = ServerCore.getRuntimes();
gercan652c9282004-11-07 19:04:18 +0000122 int suffix = 1;
123 String suffixName=name;
gercan202cf232004-12-04 11:58:11 +0000124 for(int i=0;i<list.length;i++)
gercan652c9282004-11-07 19:04:18 +0000125 {
gercan202cf232004-12-04 11:58:11 +0000126 if(list[i].getName().equals(name)|| list[i].getName().equals(suffixName))
gercan652c9282004-11-07 19:04:18 +0000127 suffix++;
128 suffixName= name+" "+suffix;
129 }
130
131 if(suffix>1)
132 return suffixName;
133 return name;
134 }
135
gercan53c00bb2005-05-18 19:54:52 +0000136 private GenericServerRuntime getRuntimeDelegate()
gercan652c9282004-11-07 19:04:18 +0000137 {
gercan202cf232004-12-04 11:58:11 +0000138 if(fRuntimeDelegate == null)
139 {
gercan66440342005-03-08 22:20:47 +0000140 IRuntimeWorkingCopy wc = (IRuntimeWorkingCopy)getTaskModel().getObject(TaskModel.TASK_RUNTIME);
gercand6595ef2004-12-04 15:28:45 +0000141 if(wc==null)
142 return null;
gercanf747ac02005-06-05 21:51:55 +0000143 fRuntimeDelegate = (GenericServerRuntime)wc.getAdapter(GenericServerRuntime.class);
144 if(fRuntimeDelegate==null)
145 fRuntimeDelegate= (GenericServerRuntime)wc.loadAdapter(GenericServerRuntime.class,new NullProgressMonitor());
gercan202cf232004-12-04 11:58:11 +0000146 }
147 return fRuntimeDelegate;
gercan652c9282004-11-07 19:04:18 +0000148 }
gercan2957b582004-11-16 17:20:28 +0000149 /* (non-Javadoc)
150 * @see org.eclipse.jst.server.generic.internal.ui.ServerDefinitionTypeAwareWizardFragment#description()
151 */
152 public String description() {
gercand2d5c192005-03-16 18:01:19 +0000153 String rName = getRuntimeName();
154 if(rName == null || rName.length()<1)
155 rName="Generic";
gercand04ac652005-05-25 20:06:30 +0000156 return GenericServerUIMessages.bind(GenericServerUIMessages.runtimeWizardDescription,rName);
gercan2957b582004-11-16 17:20:28 +0000157 }
158 /* (non-Javadoc)
159 * @see org.eclipse.jst.server.generic.internal.ui.ServerDefinitionTypeAwareWizardFragment#title()
160 */
161 public String title() {
gercand2d5c192005-03-16 18:01:19 +0000162 String rName = getRuntimeName();
163 if(rName == null || rName.length()<1)
164 rName="Generic";
gercand04ac652005-05-25 20:06:30 +0000165 return GenericServerUIMessages.bind(GenericServerUIMessages.runtimeWizardTitle,rName);
gercand2d5c192005-03-16 18:01:19 +0000166 }
167
168 private String getRuntimeName()
169 {
170 if(getRuntimeDelegate()!=null && getRuntimeDelegate().getRuntime()!=null)
171 return getRuntimeDelegate().getRuntime().getName();
172 return null;
gercan2957b582004-11-16 17:20:28 +0000173 }
174
gercan652c9282004-11-07 19:04:18 +0000175}