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: 2cd3b5839b18e64278661e6d410d2cfed596bbc5 (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
/*******************************************************************************
 * Copyright (c) 2003, 2004 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 Nov 13, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipse.jst.j2ee.application.internal.operations;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;

/**
 * @author jsholl
 * 
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class UpdateManifestDataModelProvider extends AbstractDataModelProvider implements UpdateManifestDataModelProperties {

	public Set getPropertyNames() {
		Set propertyNames = super.getPropertyNames();
		propertyNames.add(PROJECT_NAME);
		propertyNames.add(JAR_LIST);
		propertyNames.add(JAR_LIST_TEXT_UI);
		propertyNames.add(MERGE);
		propertyNames.add(MAIN_CLASS);
		propertyNames.add(MANIFEST_FILE);
		return propertyNames;
	}

	public Object getDefaultProperty(String propertyName) {
		if (propertyName.equals(MERGE)) {
			return Boolean.TRUE;
		} else if (propertyName.equals(JAR_LIST)) {
			return new ArrayList();
		} else if (propertyName.equals(JAR_LIST_TEXT_UI)) {
			return getClasspathAsString();
		}
		return super.getDefaultProperty(propertyName);
	}

	public boolean propertySet(String propertyName, Object propertyValue) {
		boolean set = super.propertySet(propertyName, propertyValue);
		if (propertyName.equals(JAR_LIST) && isPropertySet(JAR_LIST_TEXT_UI))
			setProperty(JAR_LIST_TEXT_UI, getClasspathAsString());
		return set;
	}

	public IProject getProject() {
		String projectName = (String) getProperty(PROJECT_NAME);
		return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
	}

	public String getClasspathAsString() {
		List classpathList = (List) getProperty(JAR_LIST);
		return convertClasspathListToString(classpathList);
	}

	public static String convertClasspathListToString(List list) {
		String classpathString = ""; //$NON-NLS-1$
		for (int i = 0; i < list.size(); i++) {
			classpathString += ((String) list.get(i)) + " "; //$NON-NLS-1$
		}
		return classpathString.trim();
	}

	public static List convertClasspathStringToList(String string) {
		List list = new ArrayList();
		StringTokenizer tokenizer = new StringTokenizer(string, " "); //$NON-NLS-1$
		while (tokenizer.hasMoreTokens()) {
			list.add(tokenizer.nextToken());
		}
		return list;
	}
	
	public IDataModelOperation getDefaultOperation() {
		return new UpdateManifestOperation(model);
	}
}

Back to the top