gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | ***************************************************************************/ |
gercan | 6644034 | 2005-03-08 22:20:47 +0000 | [diff] [blame] | 31 | package org.eclipse.jst.server.generic.ui.internal; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 32 | |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 33 | import java.util.Map; |
| 34 | import org.eclipse.core.runtime.IStatus; |
gercan | d6595ef | 2004-12-04 15:28:45 +0000 | [diff] [blame] | 35 | import org.eclipse.core.runtime.NullProgressMonitor; |
gercan | 6644034 | 2005-03-08 22:20:47 +0000 | [diff] [blame] | 36 | import org.eclipse.jst.server.generic.core.internal.GenericServerRuntime; |
ndai | d723dcd | 2004-11-20 21:19:43 +0000 | [diff] [blame] | 37 | import org.eclipse.jst.server.generic.servertype.definition.ServerRuntime; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 38 | import org.eclipse.swt.widgets.Composite; |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 39 | import org.eclipse.wst.server.core.IRuntime; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 40 | import org.eclipse.wst.server.core.IRuntimeType; |
| 41 | import org.eclipse.wst.server.core.IRuntimeWorkingCopy; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 42 | import org.eclipse.wst.server.core.ServerCore; |
gercan | 6644034 | 2005-03-08 22:20:47 +0000 | [diff] [blame] | 43 | import org.eclipse.wst.server.core.TaskModel; |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 44 | import org.eclipse.wst.server.core.model.RuntimeDelegate; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 45 | import org.eclipse.wst.server.ui.wizard.IWizardHandle; |
| 46 | |
| 47 | /** |
| 48 | * A serverDefinitionType aware wizard for defining runtimes. |
| 49 | * |
| 50 | * @author Gorkem Ercan |
| 51 | */ |
| 52 | public class GenericServerRuntimeWizardFragment extends ServerDefinitionTypeAwareWizardFragment { |
| 53 | |
gercan | 53c00bb | 2005-05-18 19:54:52 +0000 | [diff] [blame] | 54 | private GenericServerRuntime fRuntimeDelegate; |
gercan | f7be76a | 2005-05-22 22:32:09 +0000 | [diff] [blame] | 55 | private GenericServerCompositeDecorator[] fDecorators; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Constructor |
| 59 | */ |
| 60 | public GenericServerRuntimeWizardFragment() { |
| 61 | super(); |
| 62 | } |
| 63 | /* (non-Javadoc) |
gercan | d2d5c19 | 2005-03-16 18:01:19 +0000 | [diff] [blame] | 64 | * @see org.eclipse.wst.server.ui.wizard.IWizardFragment#isComplete() |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 65 | */ |
| 66 | public boolean isComplete() { |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 67 | RuntimeDelegate runtime = getRuntimeDelegate(); |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 68 | 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) { |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 75 | Map properties= null; |
gercan | 985a66b | 2005-04-23 06:25:45 +0000 | [diff] [blame] | 76 | ServerRuntime definition=null; |
gercan | f747ac0 | 2005-06-05 21:51:55 +0000 | [diff] [blame] | 77 | if(getRuntimeDelegate()!=null){ |
| 78 | properties = getRuntimeDelegate().getServerInstanceProperties(); |
gercan | 985a66b | 2005-04-23 06:25:45 +0000 | [diff] [blame] | 79 | definition = getServerTypeDefinition(getServerDefinitionId(),properties); |
| 80 | } |
gercan | f747ac0 | 2005-06-05 21:51:55 +0000 | [diff] [blame] | 81 | fDecorators= new GenericServerCompositeDecorator[2]; |
gercan | f60c5c3 | 2005-05-24 20:35:45 +0000 | [diff] [blame] | 82 | fDecorators[0]= new JRESelectDecorator(getRuntimeDelegate()); |
| 83 | fDecorators[1]= new ServerTypeDefinitionRuntimeDecorator(definition,properties,getWizard(),getRuntimeDelegate()); |
gercan | f7be76a | 2005-05-22 22:32:09 +0000 | [diff] [blame] | 84 | GenericServerComposite composite = new GenericServerComposite(parent,fDecorators); |
gercan | f747ac0 | 2005-06-05 21:51:55 +0000 | [diff] [blame] | 85 | |
gercan | f7be76a | 2005-05-22 22:32:09 +0000 | [diff] [blame] | 86 | } |
| 87 | |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 88 | |
gercan | f7be76a | 2005-05-22 22:32:09 +0000 | [diff] [blame] | 89 | private String getServerDefinitionId(){ |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 90 | String currentDefinition= null; |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 91 | if(getRuntimeDelegate()!=null) |
gercan | d2d5c19 | 2005-03-16 18:01:19 +0000 | [diff] [blame] | 92 | currentDefinition = getRuntimeDelegate().getRuntime().getRuntimeType().getId(); |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 93 | if(currentDefinition!= null && currentDefinition.length()>0) |
| 94 | { |
| 95 | return currentDefinition; |
| 96 | } |
| 97 | return null; |
| 98 | } |
| 99 | |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | /* (non-Javadoc) |
| 103 | * @see org.eclipse.wst.server.ui.wizard.IWizardFragment#enter() |
| 104 | */ |
| 105 | public void enter() { |
gercan | f747ac0 | 2005-06-05 21:51:55 +0000 | [diff] [blame] | 106 | if(getRuntimeDelegate()!=null) |
| 107 | getRuntimeDelegate().getRuntimeWorkingCopy().setName(createName()); |
gercan | f7be76a | 2005-05-22 22:32:09 +0000 | [diff] [blame] | 108 | for (int i = 0; i < fDecorators.length; i++) { |
| 109 | if(fDecorators[i].validate()) |
| 110 | return; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
gercan | 80ccf06 | 2005-06-07 05:37:59 +0000 | [diff] [blame^] | 114 | |
gercan | a14b9c9 | 2005-03-07 22:21:24 +0000 | [diff] [blame] | 115 | |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 116 | private String createName() |
| 117 | { |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 118 | RuntimeDelegate dl = getRuntimeDelegate(); |
| 119 | IRuntimeType runtimeType = dl.getRuntime().getRuntimeType(); |
gercan | d04ac65 | 2005-05-25 20:06:30 +0000 | [diff] [blame] | 120 | String name = GenericServerUIMessages.bind(GenericServerUIMessages.runtimeName,runtimeType.getName()); |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 121 | IRuntime[] list = ServerCore.getRuntimes(); |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 122 | int suffix = 1; |
| 123 | String suffixName=name; |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 124 | for(int i=0;i<list.length;i++) |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 125 | { |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 126 | if(list[i].getName().equals(name)|| list[i].getName().equals(suffixName)) |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 127 | suffix++; |
| 128 | suffixName= name+" "+suffix; |
| 129 | } |
| 130 | |
| 131 | if(suffix>1) |
| 132 | return suffixName; |
| 133 | return name; |
| 134 | } |
| 135 | |
gercan | 53c00bb | 2005-05-18 19:54:52 +0000 | [diff] [blame] | 136 | private GenericServerRuntime getRuntimeDelegate() |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 137 | { |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 138 | if(fRuntimeDelegate == null) |
| 139 | { |
gercan | 6644034 | 2005-03-08 22:20:47 +0000 | [diff] [blame] | 140 | IRuntimeWorkingCopy wc = (IRuntimeWorkingCopy)getTaskModel().getObject(TaskModel.TASK_RUNTIME); |
gercan | d6595ef | 2004-12-04 15:28:45 +0000 | [diff] [blame] | 141 | if(wc==null) |
| 142 | return null; |
gercan | f747ac0 | 2005-06-05 21:51:55 +0000 | [diff] [blame] | 143 | fRuntimeDelegate = (GenericServerRuntime)wc.getAdapter(GenericServerRuntime.class); |
| 144 | if(fRuntimeDelegate==null) |
| 145 | fRuntimeDelegate= (GenericServerRuntime)wc.loadAdapter(GenericServerRuntime.class,new NullProgressMonitor()); |
gercan | 202cf23 | 2004-12-04 11:58:11 +0000 | [diff] [blame] | 146 | } |
| 147 | return fRuntimeDelegate; |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 148 | } |
gercan | 2957b58 | 2004-11-16 17:20:28 +0000 | [diff] [blame] | 149 | /* (non-Javadoc) |
| 150 | * @see org.eclipse.jst.server.generic.internal.ui.ServerDefinitionTypeAwareWizardFragment#description() |
| 151 | */ |
| 152 | public String description() { |
gercan | d2d5c19 | 2005-03-16 18:01:19 +0000 | [diff] [blame] | 153 | String rName = getRuntimeName(); |
| 154 | if(rName == null || rName.length()<1) |
| 155 | rName="Generic"; |
gercan | d04ac65 | 2005-05-25 20:06:30 +0000 | [diff] [blame] | 156 | return GenericServerUIMessages.bind(GenericServerUIMessages.runtimeWizardDescription,rName); |
gercan | 2957b58 | 2004-11-16 17:20:28 +0000 | [diff] [blame] | 157 | } |
| 158 | /* (non-Javadoc) |
| 159 | * @see org.eclipse.jst.server.generic.internal.ui.ServerDefinitionTypeAwareWizardFragment#title() |
| 160 | */ |
| 161 | public String title() { |
gercan | d2d5c19 | 2005-03-16 18:01:19 +0000 | [diff] [blame] | 162 | String rName = getRuntimeName(); |
| 163 | if(rName == null || rName.length()<1) |
| 164 | rName="Generic"; |
gercan | d04ac65 | 2005-05-25 20:06:30 +0000 | [diff] [blame] | 165 | return GenericServerUIMessages.bind(GenericServerUIMessages.runtimeWizardTitle,rName); |
gercan | d2d5c19 | 2005-03-16 18:01:19 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | private String getRuntimeName() |
| 169 | { |
| 170 | if(getRuntimeDelegate()!=null && getRuntimeDelegate().getRuntime()!=null) |
| 171 | return getRuntimeDelegate().getRuntime().getName(); |
| 172 | return null; |
gercan | 2957b58 | 2004-11-16 17:20:28 +0000 | [diff] [blame] | 173 | } |
| 174 | |
gercan | 652c928 | 2004-11-07 19:04:18 +0000 | [diff] [blame] | 175 | } |