Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d7ffa44a77f2e01c8864e03bcecf04c5017e5d4d (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) 2000, 2005 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
 *******************************************************************************/
package org.eclipse.compare.examples.xml;

import java.util.*;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.window.Window;

/**
 * Button to create a new id mapping scheme
 */
public class CreateNewIdMapAction extends Action {

	private HashMap fIdMaps;// HashMap ( idname -> HashMap (signature -> id) )
	private HashMap fIdMapsInternal;
	private HashMap fIdExtensionToName;
	
	public CreateNewIdMapAction(XMLStructureViewer viewer) {		
		setImageDescriptor(XMLPlugin.getDefault().getImageDescriptor("obj16/addidmap.gif")); //$NON-NLS-1$
		setToolTipText(XMLCompareMessages.XMLStructureViewer_newtask); 
	}
	
	@Override
	public void run() {
		XMLPlugin plugin= XMLPlugin.getDefault();
		fIdMapsInternal= plugin.getIdMapsInternal();//fIdMapsInternal is only read, not modified
		
		fIdMaps = new HashMap();
		HashMap PluginIdMaps = plugin.getIdMaps();
		Set keySet = PluginIdMaps.keySet();
		for (Iterator iter = keySet.iterator(); iter.hasNext(); ) {
			String key = (String) iter.next();
			fIdMaps.put(key, ((HashMap)PluginIdMaps.get(key)).clone());
		}
		
		fIdExtensionToName= new HashMap();
		HashMap PluginIdExtensionToName= plugin.getIdExtensionToName();
		keySet= PluginIdExtensionToName.keySet();
		for (Iterator iter= keySet.iterator(); iter.hasNext(); ) {
			String key= (String) iter.next();
			fIdExtensionToName.put(key, PluginIdExtensionToName.get(key));
		}
		
		IdMap idmap = new IdMap(false);
		XMLCompareAddIdMapDialog dialog= new XMLCompareAddIdMapDialog(XMLPlugin.getActiveWorkbenchShell(),idmap,fIdMaps,fIdMapsInternal,fIdExtensionToName,false);
		if (dialog.open() == Window.OK) {
			if (!fIdMaps.containsKey(idmap.getName())) {
				fIdMaps.put(idmap.getName(),new HashMap());
				if (!idmap.getExtension().equals("")) //$NON-NLS-1$
					fIdExtensionToName.put(idmap.getExtension(),idmap.getName());
				XMLPlugin.getDefault().setIdMaps(fIdMaps,fIdExtensionToName,null,false);
			}
		}
	}
}

Back to the top