Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: bef30d4d1622e4f3bc30fcb5de96738ac7630dd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * Copyright (c) 2003, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
/*
 * Created on Aug 17, 2003
 * 
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipse.jst.j2ee.internal.wizard;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jem.util.logger.proxy.Logger;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.ServerUtil;

/**
 * @author vijayb
 * 
 * To change the template for this generated type comment go to Window>Preferences>Java>Code
 * Generation>Code and Comments
 */
public class ServerTargetUIHelper {
	/**
	 *  
	 */
	public ServerTargetUIHelper() {
		super();
	}

	public static String getSelectedServerTargetString(Combo serverTargetCombo) {
		if (serverTargetCombo.getSelectionIndex() != -1)
			return serverTargetCombo.getItem(serverTargetCombo.getSelectionIndex());
		return null;
	}

	/**
	 * @return
	 */
	public static int getSelectedServerTargetStringIndex(Combo serverTargetCombo) {
		return serverTargetCombo.getSelectionIndex();
	}

//	private static void setServerTargetForProject(Shell shell, IProject project, IRuntime runtime) {
//		//ServerTargetHelper.cleanUpNonServerTargetClasspath(project);
//		setServerTarget(shell, project, runtime, null);
//	}

	/**
	 * @param earProject
	 * @param moduleProject
	 * @return
	 */
	public static boolean setModuleServerTargetIfNecessary(IProject earProject, IProject moduleProject, Shell shell) {
		return true;
	}

	//	private static String getEARJ2EELevel(IProject earProject) {
	//		EARNatureRuntime nature = EARNatureRuntime.getRuntime(earProject);
	//		String j2eeLevel = null;
	//		int natureID = nature.getJ2EEVersion();
	//		switch (natureID) {
	//			case (J2EEVersionConstants.J2EE_1_2_ID) :
	//				j2eeLevel = J2EEVersionConstants.VERSION_1_2_TEXT;
	//				break;
	//			case (J2EEVersionConstants.J2EE_1_3_ID) :
	//				j2eeLevel = J2EEVersionConstants.VERSION_1_3_TEXT;
	//				break;
	//			case (J2EEVersionConstants.J2EE_1_4_ID) :
	//				j2eeLevel = J2EEVersionConstants.VERSION_1_4_TEXT;
	//				break;
	//			default :
	//				j2eeLevel = J2EEVersionConstants.VERSION_1_4_TEXT;
	//				break;
	//		}
	//		return j2eeLevel;
	//	}

	public static void setServerTarget(Shell shell, IProject project, IRuntime runtime, IProgressMonitor monitor) {
//		try {
//			ServerCore.getProjectProperties(project).setRuntimeTarget(runtime, monitor);
//		} catch (CoreException e) {
//			Logger.getLogger().logError(e);
//		}
	}


	public static ServerTargetComboHelper getValidServerTargetComboItems(String j2eeType, String selectedVersion) {
		IRuntime[] validServerTargets = ServerUtil.getRuntimes(j2eeType, selectedVersion);
		String[] serverTargetList = null;
		if (validServerTargets.length>0) {
			int serverTargetListSize = validServerTargets.length;
			serverTargetList = new String[serverTargetListSize];
			for (int i = 0; i < validServerTargets.length; i++) {
				IRuntime runtime = validServerTargets[i];
				serverTargetList[i] = runtime.getName() + " (" + runtime.getRuntimeType().getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
			}
		}
		return new ServerTargetComboHelper(Arrays.asList(validServerTargets), serverTargetList);
	}

	/**
	 * @param project
	 */
	public static void runEarValidation(IProject project) {
		try {
			IRunnableWithProgress runnable = EARValidationHelper.createValidationRunnable(project);
			runnable.run(null);
		} catch (InterruptedException ie) {
			Logger.getLogger().logError(ie);
		} catch (InvocationTargetException ite) {
			Logger.getLogger().logError(ite);
		}
	}
}

Back to the top