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: e67743a9f01628cbda4c354050221686524b66ce (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
/***************************************************************************************************
 * Copyright (c) 2007 Eteration A.S. and Gorkem Ercan. 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: Gorkem Ercan - initial API and implementation
 *               
 **************************************************************************************************/
package org.eclipse.jst.server.generic.ui.internal.editor;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.server.generic.core.internal.GenericServer;
import org.eclipse.jst.server.generic.ui.internal.GenericUiPlugin;
import org.eclipse.wst.server.core.IServerWorkingCopy;

public class UpdateServerPropertyOperation extends AbstractOperation {
	private GenericServer fGenericServer;
	private String  fPropertyName;
	private String fPRopertyValue;
	private String fOldValue;
	
	public UpdateServerPropertyOperation(IServerWorkingCopy server, String name, String propertyName, String propertyValue) {
		super(name);
		if(server!=null){
			fGenericServer = (GenericServer)server.loadAdapter(GenericServer.class, new NullProgressMonitor());
		}
		fPropertyName=propertyName;
		fPRopertyValue=propertyValue;	
	}
	
	public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
		Map map = new HashMap( fGenericServer.getServerInstanceProperties() );
		if(map.containsKey(fPropertyName))
		{
            fOldValue = ( String )map.get( fPropertyName );
			map.put(fPropertyName, fPRopertyValue);
            fGenericServer.setServerInstanceProperties( map );
			return null;
		}
		return new Status(IStatus.ERROR,GenericUiPlugin.PLUGIN_ID,0,"Property can not be found",null); //$NON-NLS-1$
	}

	
	
	public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
		return execute(monitor,info);
	}

	public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
		Map map = new HashMap(fGenericServer.getServerInstanceProperties());
		map.put(fPropertyName, fOldValue);
        fGenericServer.setServerInstanceProperties(map);
		return null;
		}
}

Back to the top