diff options
Diffstat (limited to 'examples/org.eclipse.compare.examples.xml/src/org')
28 files changed, 0 insertions, 6507 deletions
diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AbstractMatching.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AbstractMatching.java deleted file mode 100644 index 30be2d0bd..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AbstractMatching.java +++ /dev/null @@ -1,315 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.ArrayList; -import java.util.Vector; - -import org.eclipse.compare.rangedifferencer.IRangeComparator; -import org.eclipse.compare.rangedifferencer.RangeDifference; -import org.eclipse.compare.rangedifferencer.RangeDifferencer; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * @version 1.0 - * @author - */ -public abstract class AbstractMatching { - - protected static final int NO_ENTRY = -1;//value with which fDT elements are initialized - protected static final String SIGN_ELEMENT= XMLStructureCreator.SIGN_ELEMENT; - int[][] fDT;//Distance Table; 1st index from fNLeft, 2nd index from fNRight - ArrayList[][] fDT_Matchings;//Mathing entries of children for a match. 1st index from fNLeft, 2nd index from fNRight - Vector fNLeft; - Vector fNRight; - Vector fMatches; - - /* methods used for match */ - - /* finds all the leaves of a tree and puts them in a vector */ - protected void findLeaves(XMLNode root, ArrayList leaves) { - if (isLeaf(root)) { - leaves.add(root); - } else { - Object[] children = root.getChildren(); - for (int i=0; i<children.length; i++) - findLeaves((XMLNode) children[i], leaves); - } - } - - /* true if x is a leaf */ - protected boolean isLeaf(XMLNode x) { - if (x == null) return true; - return x.getChildren() == null || x.getChildren().length <= 0; - } - - /* Numbers all nodes of tree. The number of x is its index in the vector numbering */ - protected void numberNodes(XMLNode root, Vector numbering) { - if (root != null) { - numbering.add(root); - Object[] children = root.getChildren(); - if (children != null) { - for (int i=0; i<children.length; i++) - numberNodes((XMLNode) children[i], numbering); - } - } - } - - /* counts # of nodes in tree including root */ - protected int countNodes(XMLNode root) { - if (root == null) return 0; - int count = 1; - if (isLeaf(root)) return count; - Object[] children = root.getChildren(); - for (int i=0; i<children.length; i++) - count+=countNodes((XMLNode) children[i]); - return count; - } - - /* returns index of node x in fNLeft */ - protected int indexOfLN (XMLNode x) { - int i; - for (i=0; (i<fNLeft.size()) && (fNLeft.elementAt(i) != x); i++); - return i; - } - - /* returns index of node y in fNRight */ - protected int indexOfRN (XMLNode y) { - int j; - for (j=0; (j<fNRight.size()) && (fNRight.elementAt(j) != y); j++); - return j; - } - -/* for testing */ - public Vector getMatches() { - return fMatches; - } - - protected class XMLComparator implements IRangeComparator { - - private Object[] fXML_elements; - - public XMLComparator(Object[] xml_elements) { - fXML_elements= xml_elements; - } - - /* - * @see IRangeComparator#getRangeCount() - */ - public int getRangeCount() { - return fXML_elements.length; - } - - /* - * @see IRangeComparator#rangesEqual(int, IRangeComparator, int) - */ - public boolean rangesEqual( - int thisIndex, - IRangeComparator other_irc, - int otherIndex) { - - if (other_irc instanceof XMLComparator) { - XMLComparator other= (XMLComparator) other_irc; - //return ((XMLNode)fXML_elements[thisIndex]).subtreeEquals(other.getXML_elements()[otherIndex]); - - //ordered compare of subtrees - //boolean result= ((XMLNode)fXML_elements[thisIndex]).subtreeEquals(other.getXML_elements()[otherIndex]); - - //taking ids into account - boolean sameId= false; - XMLNode thisNode= (XMLNode)fXML_elements[thisIndex]; - XMLNode otherNode= (XMLNode)other.getXML_elements()[otherIndex]; - if ( thisNode.usesIDMAP() && otherNode.usesIDMAP() ) { - if ( otherNode.getOrigId().equals(thisNode.getOrigId()) ) { - sameId= true; - } - } - - //unordered compare of subtrees - int distance= dist((XMLNode)other.getXML_elements()[otherIndex] , (XMLNode)fXML_elements[thisIndex]); - return sameId || distance == 0; - } - return false; - } - - /* - * @see IRangeComparator#skipRangeComparison(int, int, IRangeComparator) - */ - public boolean skipRangeComparison( - int length, - int maxLength, - IRangeComparator other) { - return false; - } - - public Object[] getXML_elements() { - return fXML_elements; - } - - } - - /* represents a matching between a node in the Left tree and a node in the Right tree */ - class Match { - public XMLNode fx; - public XMLNode fy; - - Match(XMLNode x, XMLNode y) { - fx = x; - fy = y; - } - - public boolean equals(Object obj) { - if (obj instanceof Match) { - Match m = (Match) obj; - if (m != null) - return fx == m.fx && fy == m.fy; - } - return false; - } - } - - protected int handleRangeDifferencer(Object[] xc_elements, Object[] yc_elements, ArrayList DTMatching, int distance) { - RangeDifference[] differences= RangeDifferencer.findDifferences(new XMLComparator(xc_elements), new XMLComparator(yc_elements)); - - int cur_pos_left= 0; - int cur_pos_right= 0; - for (int i= 0; i < differences.length; i++) { - RangeDifference rd= differences[i]; - int equal_length= rd.leftStart(); - //handle elements before current range which are unchanged - while (cur_pos_left < equal_length) { - //assuming XMLComparator has already filled fDT and fDT_Matchings for subtrees - //rooted at xc_elements[cur_pos_left] and yc_elements[cur_pos_right] -// if ( fDT[indexOfLN( (XMLNode)xc_elements[cur_pos_left])][indexOfRN( (XMLNode)yc_elements[cur_pos_right])] != 0) -// System.out.println("distance not 0"); -// distance += fDT[indexOfLN( (XMLNode)xc_elements[cur_pos_left])][indexOfRN( (XMLNode)yc_elements[cur_pos_right])]; - //DTMatching.addAll(fDT_Matchings[index_left][index_right]); - DTMatching.add(new Match( (XMLNode)xc_elements[cur_pos_left], (XMLNode)yc_elements[cur_pos_right])); - cur_pos_left++; - cur_pos_right++; - } - //now handle RangeDifference rd[i] - int smaller_length, greater_length; - boolean leftGreater= rd.leftLength() > rd.rightLength(); - if (leftGreater) { - smaller_length= rd.rightLength(); - greater_length= rd.leftLength(); - } else { - smaller_length= rd.leftLength(); - greater_length= rd.rightLength(); - } - - //handle elements elements in range - for (int j=0; j < smaller_length; j++) { - distance += dist((XMLNode) xc_elements[cur_pos_left], (XMLNode) yc_elements[cur_pos_right]); - DTMatching.add(new Match( (XMLNode)xc_elements[cur_pos_left], (XMLNode)yc_elements[cur_pos_right])); - cur_pos_left++; - cur_pos_right++; - } - //int cur_pos_greater= (leftGreater)?cur_pos_left:cur_pos_right; - if (leftGreater) { - for (int j=smaller_length; j < greater_length; j++) { - distance += countNodes((XMLNode) xc_elements[cur_pos_left]); - DTMatching.add(new Match( (XMLNode)xc_elements[cur_pos_left], null)); - cur_pos_left++; - } - } else { - for (int j=smaller_length; j < greater_length; j++) { - distance += countNodes((XMLNode) yc_elements[cur_pos_right]); - DTMatching.add(new Match( null, (XMLNode)yc_elements[cur_pos_right])); - cur_pos_right++; - } - } -// for (int j=smaller_length; j < greater_length; j++) { -// distance += countNodes((XMLNode) xc_elements[cur_pos_greater]); -// cur_pos_greater++; -// } -// if (leftGreater) -// cur_pos_left= cur_pos_greater; -// else -// cur_pos_right= cur_pos_greater; - } - - for (int i= cur_pos_left; i < xc_elements.length; i++) { - //distance += fDT[indexOfLN( (XMLNode)xc_elements[cur_pos_left])][indexOfRN( (XMLNode)yc_elements[cur_pos_right])]; - //DTMatching.addAll(fDT_Matchings[index_left][index_right]); - DTMatching.add(new Match( (XMLNode)xc_elements[cur_pos_left], (XMLNode)yc_elements[cur_pos_right])); - cur_pos_left++; - cur_pos_right++; - } - - return distance; - } - - abstract public void match(XMLNode LeftTree, XMLNode RightTree, boolean rightTreeIsAncestor, IProgressMonitor monitor) throws InterruptedException; - - protected int dist(XMLNode x, XMLNode y) { - //System.out.println("dist( "+x.getSignature()+" , "+y.getSignature()+")"); - int ret= NO_ENTRY; - - int index_x= indexOfLN(x); - int index_y= indexOfRN(y); - if (fDT[index_x][index_y] != NO_ENTRY) return fDT[index_x][index_y]; - - if (isLeaf(x) && isLeaf(y)) { - if (x.getXMLType() == XMLStructureCreator.TYPE_ELEMENT) { - if ( x.getSignature().equals(y.getSignature()) ) { - ret= 0; - fDT[index_x][index_y] = ret; - return ret; - } else { - ret= 2; - fDT[index_x][index_y] = ret; - return ret; - } - } else if (x.getXMLType() == XMLStructureCreator.TYPE_ATTRIBUTE || x.getXMLType() == XMLStructureCreator.TYPE_TEXT) { - if ( x.getSignature().equals(y.getSignature()) ) { - if (x.getValue().equals(y.getValue())) { - ret= 0; - fDT[index_x][index_y] = ret; - return ret; - } else { - ret= 1; - fDT[index_x][index_y] = ret; - return ret; - } - } - else { - ret= 2; - fDT[index_x][index_y] = ret; - return ret; - } - } - } else {//x or y are not leaves - if ( !x.getSignature().equals(y.getSignature()) ) { - ret= countNodes(x) + countNodes(y); - fDT[index_x][index_y] = ret; - return ret; - } else {//x.getSignature().equals(y.getSignature()) - if (isLeaf(x)) { - ret= countNodes(y)-1; - fDT[index_x][index_y] = ret; - return ret; - } - if (isLeaf(y)) { - ret= countNodes(x)-1; - fDT[index_x][index_y] = ret; - return ret; - } - //both x and y have children - return handleXandYnotLeaves(x,y); - } - } - return ret; - } - - abstract int handleXandYnotLeaves(XMLNode x, XMLNode y); -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AttributesImpl.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AttributesImpl.java deleted file mode 100644 index 2b4f1e444..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AttributesImpl.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import org.xml.sax.Attributes; - -/** - * An Attributes implementation that can perform more operations - * than the attribute list helper supplied with the standard SAX2 - * distribution. - */ -public class AttributesImpl implements Attributes { - - /** Head node. */ - private ListNode fHead; - - /** Tail node. */ - private ListNode fTail; - - /** Length. */ - private int fLength; - - - /** Returns the number of attributes. */ - public int getLength() { - return fLength; - } - - /** Returns the index of the specified attribute. */ - public int getIndex(String raw) { - ListNode place= fHead; - int index= 0; - while (place != null) { - if (place.raw.equals(raw)) { - return index; - } - index++; - place= place.next; - } - return -1; - } - - /** Returns the index of the specified attribute. */ - public int getIndex(String uri, String local) { - ListNode place= fHead; - int index= 0; - while (place != null) { - if (place.uri.equals(uri) && place.local.equals(local)) { - return index; - } - index++; - place= place.next; - } - return -1; - } - - /** Returns the attribute URI by index. */ - public String getURI(int index) { - - ListNode node= getListNodeAt(index); - return node != null ? node.uri : null; - } - - /** Returns the attribute local name by index. */ - public String getLocalName(int index) { - - ListNode node= getListNodeAt(index); - return node != null ? node.local : null; - } - - /** Returns the attribute raw name by index. */ - public String getQName(int index) { - - ListNode node= getListNodeAt(index); - return node != null ? node.raw : null; - - } - - /** Returns the attribute type by index. */ - public String getType(int index) { - - ListNode node= getListNodeAt(index); - return (node != null) ? node.type : null; - } - - /** Returns the attribute type by uri and local. */ - public String getType(String uri, String local) { - - ListNode node= getListNode(uri, local); - return (node != null) ? node.type : null; - - } - - /** Returns the attribute type by raw name. */ - public String getType(String raw) { - - ListNode node= getListNode(raw); - return (node != null) ? node.type : null; - } - - /** Returns the attribute value by index. */ - public String getValue(int index) { - - ListNode node= getListNodeAt(index); - return (node != null) ? node.value : null; - } - - /** Returns the attribute value by uri and local. */ - public String getValue(String uri, String local) { - - ListNode node= getListNode(uri, local); - return (node != null) ? node.value : null; - } - - /** Returns the attribute value by raw name. */ - public String getValue(String raw) { - - ListNode node= getListNode(raw); - return (node != null) ? node.value : null; - } - - /** Adds an attribute. */ - public void addAttribute(String raw, String type, String value) { - addAttribute(null, null, raw, type, value); - } - - /** Adds an attribute. */ - public void addAttribute( - String uri, - String local, - String raw, - String type, - String value) { - - ListNode node= new ListNode(uri, local, raw, type, value); - if (fLength == 0) { - fHead= node; - } else { - fTail.next= node; - } - fTail= node; - fLength++; - } - - /** Inserts an attribute. */ - public void insertAttributeAt( - int index, - String raw, - String type, - String value) { - insertAttributeAt(index, null, null, raw, type, value); - } - - /** Inserts an attribute. */ - public void insertAttributeAt( - int index, - String uri, - String local, - String raw, - String type, - String value) { - - // if list is empty, add attribute - if (fLength == 0 || index >= fLength) { - addAttribute(uri, local, raw, type, value); - return; - } - - // insert at beginning of list - ListNode node= new ListNode(uri, local, raw, type, value); - if (index < 1) { - node.next= fHead; - fHead= node; - } else { - ListNode prev= getListNodeAt(index - 1); - node.next= prev.next; - prev.next= node; - } - fLength++; - } - - /** Removes an attribute. */ - public void removeAttributeAt(int index) { - - if (fLength == 0) - return; - - if (index == 0) { - fHead= fHead.next; - if (fHead == null) { - fTail= null; - } - fLength--; - } else { - ListNode prev= getListNodeAt(index - 1); - ListNode node= getListNodeAt(index); - if (node != null) { - prev.next= node.next; - if (node == fTail) { - fTail= prev; - } - fLength--; - } - } - } - - /** Removes the specified attribute. */ - public void removeAttribute(String raw) { - removeAttributeAt(getIndex(raw)); - } - - /** Removes the specified attribute. */ - public void removeAttribute(String uri, String local) { - removeAttributeAt(getIndex(uri, local)); - } - - /** Returns the node at the specified index. */ - private ListNode getListNodeAt(int i) { - - for (ListNode place= fHead; place != null; place= place.next) { - if (--i == -1) { - return place; - } - } - return null; - } - - /** Returns the first node with the specified uri and local. */ - public ListNode getListNode(String uri, String local) { - - if (uri != null && local != null) { - ListNode place= fHead; - while (place != null) { - if (place.uri != null - && place.local != null - && place.uri.equals(uri) - && place.local.equals(local)) { - return place; - } - place= place.next; - } - } - return null; - } - - /** Returns the first node with the specified raw name. */ - private ListNode getListNode(String raw) { - - if (raw != null) { - for (ListNode place= fHead; place != null; place= place.next) { - if (place.raw != null && place.raw.equals(raw)) { - return place; - } - } - } - - return null; - } - - /** Returns a string representation of this object. */ - public String toString() { - StringBuffer str= new StringBuffer(); - - str.append('['); - str.append("len="); //$NON-NLS-1$ - str.append(fLength); - str.append(", {"); //$NON-NLS-1$ - for (ListNode place= fHead; place != null; place= place.next) { - str.append(place.toString()); - if (place.next != null) { - str.append(", "); //$NON-NLS-1$ - } - } - str.append("}]"); //$NON-NLS-1$ - - return str.toString(); - } - - /** - * An attribute node. - */ - static class ListNode { - - /** Attribute uri. */ - public String uri; - - /** Attribute local. */ - public String local; - - /** Attribute raw. */ - public String raw; - - /** Attribute type. */ - public String type; - - /** Attribute value. */ - public String value; - - /** Next node. */ - public ListNode next; - - /** Constructs a list node. */ - public ListNode( - String uri0, - String local0, - String raw0, - String type0, - String value0) { - - this.uri= uri0; - this.local= local0; - this.raw= raw0; - this.type= type0; - this.value= value0; - - } - - /** Returns string representation of this object. */ - public String toString() { - return raw != null ? raw : local; - } - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ChooseMatcherDropDownAction.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ChooseMatcherDropDownAction.java deleted file mode 100644 index 2940c98e8..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ChooseMatcherDropDownAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.*; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.*; - -import org.eclipse.jface.action.*; - - -/** - * Drop down menu to select a particular id mapping scheme - */ -class ChooseMatcherDropDownAction extends Action implements IMenuCreator { - - private XMLStructureViewer fViewer; - - public ChooseMatcherDropDownAction(XMLStructureViewer viewer) { - fViewer = viewer; - setText(XMLCompareMessages.getString("ChooseMatcherDropDownAction.text")); //$NON-NLS-1$ - setImageDescriptor(XMLPlugin.getDefault().getImageDescriptor("obj16/smartmode_co.gif")); //$NON-NLS-1$ - setToolTipText(XMLCompareMessages.getString("ChooseMatcherDropDownAction.tooltip")); //$NON-NLS-1$ - setMenuCreator(this); - } - - public void dispose() { - } - - public Menu getMenu(Menu parent) { - return null; - } - - public Menu getMenu(Control parent) { - XMLPlugin plugin= XMLPlugin.getDefault(); - Menu menu= new Menu(parent); - addActionToMenu(menu, new SelectMatcherAction(XMLStructureCreator.USE_UNORDERED, fViewer)); - addActionToMenu(menu, new SelectMatcherAction(XMLStructureCreator.USE_ORDERED, fViewer)); - new MenuItem(menu, SWT.SEPARATOR); - HashMap IdMaps = plugin.getIdMaps(); - HashMap IdMapsInternal = plugin.getIdMapsInternal(); - - Set keySetIdMaps = IdMaps.keySet(); - Set keySetIdMapsInternal = IdMapsInternal.keySet(); - ArrayList internalIdMapsAL= new ArrayList(); - for (Iterator iter_internal = keySetIdMapsInternal.iterator(); iter_internal.hasNext(); ) { - String idmap_name = (String)iter_internal.next(); - internalIdMapsAL.add(idmap_name); - } - Object[] internalIdMapsA= internalIdMapsAL.toArray(); - Arrays.sort(internalIdMapsA); - for (int i= 0; i < internalIdMapsA.length; i++) { - addActionToMenu(menu, new SelectMatcherAction((String)internalIdMapsA[i], fViewer)); - } - new MenuItem(menu, SWT.SEPARATOR); - - ArrayList userIdMapsAL= new ArrayList(); - for (Iterator iter_idmaps = keySetIdMaps.iterator(); iter_idmaps.hasNext(); ) { - String idmap_name = (String)iter_idmaps.next(); - userIdMapsAL.add(idmap_name); - } - - HashMap OrderedElements= plugin.getOrderedElements(); - Set keySetOrdered= OrderedElements.keySet(); - for (Iterator iter_orderedElements= keySetOrdered.iterator(); iter_orderedElements.hasNext();) { - String idmap_name= (String) iter_orderedElements.next(); - if (!keySetIdMaps.contains(idmap_name)) { - userIdMapsAL.add(idmap_name); - } - } - - Object[] userIdMapsA= userIdMapsAL.toArray(); - Arrays.sort(userIdMapsA); - for (int i= 0; i < userIdMapsA.length; i++) { - addActionToMenu(menu, new SelectMatcherAction((String)userIdMapsA[i], fViewer)); - } - - return menu; - } - - protected void addActionToMenu(Menu parent, Action action) { - ActionContributionItem item= new ActionContributionItem(action); - item.fill(parent, -1); - } - - public void run() { - fViewer.contentChanged(); - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/CreateNewIdMapAction.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/CreateNewIdMapAction.java deleted file mode 100644 index 9494c8fbe..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/CreateNewIdMapAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.getString("XMLStructureViewer.newtask")); //$NON-NLS-1$ - } - - 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); - } - } - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java deleted file mode 100644 index d5b86e0ba..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.core.runtime.IProgressMonitor; - -/** This class is used to find a mapping between the nodes of two xml parse trees - * When an identifier for a specific node is known, it will be used. - * Otherwise a min-cost bipartite matching must be solved. - * This algorithm uses the algorithm described in the paper - * "X-Diff: A Fast Change Detection Algorithm for XML Documents" - */ -public class GeneralMatching extends AbstractMatching { - - HungarianMethod fH; - - boolean fUseOrdered; - String[] fOrdered; - boolean fIgnoreStartsWith; - - public GeneralMatching() { - fOrdered= null; - fUseOrdered= false; - fIgnoreStartsWith= false; - } - - public GeneralMatching(ArrayList ordered) { - if (ordered != null && !ordered.isEmpty()) { - fUseOrdered= true; - fOrdered= new String[ordered.size()]; - int i= 0; - for (Iterator iter= ordered.iterator(); iter.hasNext(); i++) { - fOrdered[i]= (String) iter.next(); - } - } else { - fUseOrdered= false; - fOrdered= null; - } - //fOrderedElements= XMLPlugin.getDefault().getOrderedElements(); - } - - //x and y have children xc_orig and yc_orig, respectively - protected int unorderedMatch( - XMLNode x, - XMLNode y, - Object[] xc_orig, - Object[] yc_orig) { - ArrayList DTMatching= new ArrayList(); //Mathing Entry in fDT_Matchings - int distance= 0; //distance - - Vector xc_vect= new Vector(); - Vector yc_vect= new Vector(); - for (int i= 0; i < xc_orig.length; i++) { - if (((XMLNode) xc_orig[i]).usesIDMAP()) { - int j; - for (j= 0; - j < yc_orig.length - && !((XMLNode) yc_orig[j]).getOrigId().equals( - ((XMLNode) xc_orig[i]).getOrigId()); - j++); - if (j < yc_orig.length) { - /* not calculating their distance and adding it to variable "distance" to save time, - * as matching of subtrees is not performed. - * but better result might be achieved if this were done. - */ - //int d= dist( (XMLNode)xc_orig[i], (XMLNode)yc_orig[j] ); - //distance += d; - //fDT[indexOfLN((XMLNode)xc_orig[i])][indexOfRN((XMLNode)yc_orig[j])]= d; - DTMatching.add( - new Match((XMLNode) xc_orig[i], (XMLNode) yc_orig[j])); - } - } else - xc_vect.add(xc_orig[i]); - } - XMLNode[] xc= (XMLNode[]) xc_vect.toArray(new XMLNode[xc_vect.size()]); - for (int j= 0; j < yc_orig.length; j++) { - if (!((XMLNode) yc_orig[j]).usesIDMAP()) - yc_vect.add(yc_orig[j]); - } - XMLNode[] yc= (XMLNode[]) yc_vect.toArray(new XMLNode[yc_vect.size()]); - if (xc.length == 0 || yc.length == 0) { - if (xc.length == 0) { - for (int j= 0; j < yc.length; j++) { - distance += countNodes(yc[j]); - } - } else { //yc.length == 0 - for (int i= 0; i < xc.length; i++) { - distance += countNodes(xc[i]); - } - } - } else { - for (int i= 0; i < xc.length; i++) { - for (int j= 0; j < yc.length; j++) { - if (fDT[indexOfLN(xc[i])][indexOfRN(yc[j])] == NO_ENTRY) - dist(xc[i], yc[j]); - } - } - - /* look for Wmin (p.11) - * xc and yc are the two partitions that have to be mapped. - * But, they may not have same number of nodes - * HungarianMethod.java solves weighted matching only on complete bipatite graphs - * We must add nodes and edges to make graph complete - */ - final int array_size= - (xc.length > yc.length) ? xc.length : yc.length; - final int array_rowsize= array_size + 1; - final int array_colsize= array_size + 2; - int[][] A= new int[array_rowsize][array_colsize]; - for (int j= 0; j < array_colsize; j++) { - A[0][j]= 0; - } - /* now: A[0] = new int[] {0,0,0, ... ,0}. This first row is not used by HungarianMethod - * (Fortran77 counts Array index from 1) - */ - for (int i= 1; i < array_rowsize; i++) { - A[i][0]= 0; - for (int j= 1; j < array_colsize - 1; j++) { - A[i][j]= -1; - } - A[i][array_colsize - 1]= 0; - } - /* now A = 0, 0, 0, ... 0,0 - * 0,-1,-1, ... -1,0 - * 0,-1,-1, ... -1,0 - * ... - * 0,-1,-1, ... -1,0 - */ - for (int i_xc= 0; i_xc < xc.length; i_xc++) { - for (int i_yc= 0; i_yc < yc.length; i_yc++) { - A[i_xc + 1][i_yc + 1]= - fDT[indexOfLN(xc[i_xc])][indexOfRN(yc[i_yc])]; - } - } - int dummyCost= 0; - /* cost of dummy nodes not associated with a node in Tree, but needed - * to have a complete bipartite graph - */ - - //set dummyCost to larger than any cost in A - if (xc.length > yc.length) { - for (int i= 1; i < array_rowsize; i++) { - for (int j= 1; j <= yc.length; j++) - if (A[i][j] > dummyCost) - dummyCost= A[i][j]; - } - } else if (xc.length < yc.length) { - for (int i= 1; i <= xc.length; i++) { - for (int j= 1; j < array_colsize - 1; j++) - if (A[i][j] > dummyCost) - dummyCost= A[i][j]; - } - } else { //xc.length == yc.length - dummyCost= Integer.MAX_VALUE - 1; - } - dummyCost += 1; - - if (xc.length > yc.length) { - for (int i= 1; i < array_rowsize; i++) { - for (int j= yc.length + 1; j < array_colsize - 1; j++) { - A[i][j]= dummyCost; - } - } - } else if (xc.length < yc.length) { - for (int j= 1; j < array_colsize - 1; j++) { - for (int i= xc.length + 1; i < array_rowsize; i++) { - A[i][j]= dummyCost; - } - } - } - - //A is built. Now perform matching - int[] Matching= new int[array_rowsize]; - int[][] A2= new int[array_rowsize][array_colsize]; - for (int i= 0; i < array_rowsize; i++) { - for (int j= 0; j < array_colsize; j++) - A2[i][j]= A[i][j]; - } - fH.solve(A2, Matching); - //now Matching contains the min-cost matching of A - - for (int m= 1; m < Matching.length; m++) { - if (A[Matching[m]][m] == dummyCost) { - if (xc.length > yc.length) { - distance += countNodes(xc[Matching[m] - 1]); - //added here - DTMatching.add(new Match(xc[Matching[m] - 1], null)); - } else if (xc.length < yc.length) { - distance += countNodes(yc[m - 1]); - //added here - DTMatching.add(new Match(null, yc[m - 1])); - } - } else { - int index_x= indexOfLN(xc[Matching[m] - 1]); - int index_y= indexOfRN(yc[m - 1]); - distance += fDT[index_x][index_y]; - if ((xc[Matching[m] - 1]) - .getSignature() - .equals((yc[m - 1]).getSignature())) - DTMatching.add( - new Match(xc[Matching[m] - 1], yc[m - 1])); - else { - DTMatching.add(new Match(xc[Matching[m] - 1], null)); - DTMatching.add(new Match(null, yc[m - 1])); - } - } - } - } - fDT[indexOfLN(x)][indexOfRN(y)]= distance; - fDT_Matchings[indexOfLN(x)][indexOfRN(y)]= DTMatching; - return distance; - } - - protected int orderedMath(XMLNode x, XMLNode y) { - //assumes x and y have children - - boolean old_isw= fIgnoreStartsWith; - fIgnoreStartsWith= true; - - //both x and y have children - Object[] xc= x.getChildren(); - Object[] yc= y.getChildren(); - - ArrayList xc_elementsAL= new ArrayList(); - ArrayList xc_attrsAL= new ArrayList(); - - ArrayList yc_elementsAL= new ArrayList(); - ArrayList yc_attrsAL= new ArrayList(); - - //find attributes and elements and put them in xc_elementsAL and xc_attrsAL, respectively - for (int i= 0; i < xc.length; i++) { - XMLNode x_i= (XMLNode) xc[i]; - if (x_i.getXMLType().equals(XMLStructureCreator.TYPE_ELEMENT)) { - xc_elementsAL.add(x_i); - } else if ( - x_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) { - xc_attrsAL.add(x_i); - } - } - - //do the same for yc - for (int i= 0; i < yc.length; i++) { - XMLNode y_i= (XMLNode) yc[i]; - if (y_i.getXMLType().equals(XMLStructureCreator.TYPE_ELEMENT)) { - yc_elementsAL.add(y_i); - } else if ( - y_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) { - yc_attrsAL.add(y_i); - } - } - - Object[] xc_elements= xc_elementsAL.toArray(); - Object[] yc_elements= yc_elementsAL.toArray(); - Object[] xc_attrs= xc_attrsAL.toArray(); - Object[] yc_attrs= yc_attrsAL.toArray(); - - ArrayList DTMatching= null; - //Mathing to be added to Entry in fDT_Matchings - int distance= 0; //distance to be added to entry in fDT - - //perform unordered matching on attributes - //this updates fDT and fDT_Matchings - if (xc_attrs.length > 0 || yc_attrs.length > 0) { - if (xc_attrs.length == 0) - distance += yc_attrs.length; - else if (yc_attrs.length == 0) - distance += xc_attrs.length; - else { - unorderedMatch(x, y, xc_attrs, yc_attrs); - distance += fDT[indexOfLN(x)][indexOfRN(y)]; - DTMatching= fDT_Matchings[indexOfLN(x)][indexOfRN(y)]; - } - } - if (DTMatching == null) - DTMatching= new ArrayList(); - //perform ordered matching on element children, i.e. number them in order of appearance - - /* start new */ - distance= - handleRangeDifferencer( - xc_elements, - yc_elements, - DTMatching, - distance); - /* end new */ - - /* start: Naive ordered compare /* - // int minlength= (xc_elements.length > yc_elements.length)?yc_elements.length:xc_elements.length; - // for (int i= 0; i < minlength; i++) { - // distance += dist((XMLNode) xc_elements[i], (XMLNode) yc_elements[i]); - // DTMatching.add(new Match( (XMLNode)xc_elements[i], (XMLNode)yc_elements[i])); - // } - // if (xc_elements.length > yc_elements.length) { - // for (int i= minlength; i < xc_elements.length; i++) { - // distance += countNodes((XMLNode) xc_elements[i]); - // } - // } else if (xc_elements.length < yc_elements.length) { - // for (int i= minlength; i < yc_elements.length; i++) { - // distance += countNodes((XMLNode) yc_elements[i]); - // } - // } - /* end: Naive ordered compare */ - - fIgnoreStartsWith= old_isw; - - fDT[indexOfLN(x)][indexOfRN(y)]= distance; - fDT_Matchings[indexOfLN(x)][indexOfRN(y)]= DTMatching; - return distance; - - } - - /* matches two trees according to paper "X-Diff", p. 16 */ - public void match( - XMLNode LeftTree, - XMLNode RightTree, - boolean rightTreeIsAncestor, - IProgressMonitor monitor) - throws InterruptedException { - - //if (monitor != null) monitor.beginTask("",10); - fH= new HungarianMethod(); - fNLeft= new Vector(); - //numbering LeftTree: Mapping nodes in LeftTree to numbers to be used as array indexes - fNRight= new Vector(); - //numbering RightTree: Mapping nodes in RightTree to numbers to be used as array indexes - numberNodes(LeftTree, fNLeft); - numberNodes(RightTree, fNRight); - fDT= new int[fNLeft.size()][fNRight.size()]; - fDT_Matchings= new ArrayList[fNLeft.size()][fNRight.size()]; - for (int i= 0; i < fDT.length; i++) { - fDT[i]= new int[fNRight.size()]; - for (int j= 0; j < fDT[0].length; j++) { - fDT[i][j]= NO_ENTRY; - } - } - - ArrayList NLeft= new ArrayList(); - ArrayList NRight= new ArrayList(); - findLeaves(LeftTree, NLeft); - findLeaves(RightTree, NRight); - - /* Matching Algorithm */ - /* Step 1: Compute editing distance for (LeftTree -> RightTree)*/ - while (!NLeft.isEmpty() || !NRight.isEmpty()) { - for (ListIterator itNLeft= NLeft.listIterator(); - itNLeft.hasNext(); - ) { - XMLNode x= (XMLNode) itNLeft.next(); - for (ListIterator itNRight= NRight.listIterator(); - itNRight.hasNext(); - ) { - XMLNode y= (XMLNode) itNRight.next(); - if (x.getSignature().equals(y.getSignature())) { - // System.out.println("x: "+x.getName()); - // System.out.println("y: "+y.getName()); - if (monitor != null && monitor.isCanceled()) { - // throw new OperationCanceledException(); - throw new InterruptedException(); - // return; - } - - //if signature starts with root>project - //do not calculate dist - - //if signature is root>project - //do ordered search on children - //do unordered search on childrenb - - dist(x, y); - } - } - } - ArrayList NLeft_new= new ArrayList(); - ArrayList NRight_new= new ArrayList(); - for (ListIterator itNLeft= NLeft.listIterator(); - itNLeft.hasNext(); - ) { - XMLNode node= (XMLNode) itNLeft.next(); - if (node.getParent() != null - && !NLeft_new.contains(node.getParent())) - NLeft_new.add(node.getParent()); - } - for (ListIterator itNRight= NRight.listIterator(); - itNRight.hasNext(); - ) { - XMLNode node= (XMLNode) itNRight.next(); - if (node.getParent() != null - && !NRight_new.contains(node.getParent())) - NRight_new.add(node.getParent()); - } - NLeft= NLeft_new; - NRight= NRight_new; - } - //end of Step1 - /* Step 2: mark matchings on LeftTree and RightTree */ - fMatches= new Vector(); - if (!LeftTree.getSignature().equals(RightTree.getSignature())) { - //matching is empty - } else { - fMatches.add(new Match(LeftTree, RightTree)); - for (int i_M= 0; i_M < fMatches.size(); i_M++) { - Match m= (Match) fMatches.elementAt(i_M); - if (!isLeaf(m.fx) && !isLeaf(m.fy)) { - // if (fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ] == null) - // System.out.println("Error: ID not unique for " + m.fx.getId()); - // else - // fMatches.addAll(fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ]); - if (fDT_Matchings[indexOfLN(m.fx)][indexOfRN(m.fy)] - != null) - fMatches.addAll( - fDT_Matchings[indexOfLN(m.fx)][indexOfRN(m.fy)]); - } - } - } - //end of Step2 - /* Renumber Id of Nodes to follow Matches. Or for ancestor, copy over Id to ancestor */ - if (rightTreeIsAncestor) { - for (ListIterator it_M= fMatches.listIterator(); it_M.hasNext();) { - Match m= (Match) it_M.next(); - if (m.fx != null && m.fy != null) - m.fy.setId(m.fx.getId()); - } - } else { - int newId= 0; - for (ListIterator it_M= fMatches.listIterator(); - it_M.hasNext(); - newId++) { - Match m= (Match) it_M.next(); - if (m.fx != null) - m.fx.setId(Integer.toString(newId)); - if (m.fy != null) - m.fy.setId(Integer.toString(newId)); - // System.out.println("Matching: "+ ((m.fx != null)?m.fx.getOrigId():"null")+" -> "+((m.fx != null)?m.fx.getId():"null")+" , "+((m.fy != null)?m.fy.getOrigId():"null")+" -> "+((m.fy != null)?m.fy.getId():"null")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - } - //if (monitor != null) monitor.done(); - } - - protected int handleXandYnotLeaves(XMLNode x, XMLNode y) { - int ret= NO_ENTRY; - Object[] xc_orig= x.getChildren(); - Object[] yc_orig= y.getChildren(); - - /* handle ordered entries */ - if (fUseOrdered) { - boolean starts_with_sig= false; - boolean equals_sig= false; - String x_sig= x.getSignature(); - String y_sig= y.getSignature(); - - int i_ordered; - - if (!fIgnoreStartsWith) { - /* Normal case when algorithm runs. - * Algorithm runs bottom up from leaves to root. - * check x_sig.startsWith(fOrdered[i_ordered]) || y_sig.startsWith(fOrdered[i_ordered]) - * because if this is the case and - * !(x_sig.equals(fOrdered[j_ordered]+SIGN_ELEMENT) && y_sig.equals(fOrdered[j_ordered]+SIGN_ELEMENT)) - * i.e. the nodes are not marked for an ordered compare but x and/or y has an ancestor that is, - * then nodes x and/or y will be handled by that ancestor in orderedMatch(), which is a top-down algorithm. - * Thus, we exit the procedure dist() if this is the case. - */ - for (i_ordered= 0; i_ordered < fOrdered.length; i_ordered++) { - if (x_sig.startsWith(fOrdered[i_ordered]) - || y_sig.startsWith(fOrdered[i_ordered])) { - starts_with_sig= true; - if (x_sig.equals(y_sig)) { - for (int j_ordered= i_ordered; - j_ordered < fOrdered.length; - j_ordered++) { - if (x_sig - .equals( - fOrdered[j_ordered] + SIGN_ELEMENT)) { - equals_sig= true; - break; - } - break; - } - } - } - } - - if (starts_with_sig) { - if (equals_sig) { - return orderedMath(x, y); - } else { - return ret; - } - } - - } else { - /* when inside orderedMatch(x, y), algorithm runs recursively from a node to the leaves of the - * subtree rooted at this node. - * In this case we do not check x_sig.startsWith(fOrdered[i_ordered]) || y_sig.startsWith(fOrdered[i_ordered]) - */ - if (x_sig.equals(y_sig)) { - for (i_ordered= 0; - i_ordered < fOrdered.length; - i_ordered++) { - if (x_sig.equals(fOrdered[i_ordered] + SIGN_ELEMENT)) { - equals_sig= true; - break; - } - } - } - - if (equals_sig) { - return orderedMath(x, y); - } - } - - } - /* end of handle ordered entries */ - - return unorderedMatch(x, y, xc_orig, yc_orig); - } - -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/HungarianMethod.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/HungarianMethod.java deleted file mode 100644 index dbd2cc623..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/HungarianMethod.java +++ /dev/null @@ -1,479 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -/** This algorithm solves the assignment problem. - * It was translated from Fortran to Java. - * The original algorithm was taken from http://www.netlib.no/netlib/toms/548 - */ -public class HungarianMethod { - - public int solve(int[][] A, int[] C) { - - final int N = A.length-1; - final int NP1 = A[0].length-1; - int[] CH = new int[A.length]; - int[] LC = new int[A.length]; - int[] LR = new int[A.length]; - int[] LZ = new int[A.length]; - int[] NZ = new int[A.length]; - int[] RH = new int[A[0].length]; - int[] SLC = new int[A.length]; - int[] SLR = new int[A.length]; - int[] U = new int[A[0].length]; - int H, Q, R, S, T; - boolean while100goto120 = false; - -// SUBROUTINE ASSCT ( N, A, C, T ) 10 -// INTEGER A(130,131), C(130), CH(130), LC(130), LR(130), -// * LZ(130), NZ(130), RH(131), SLC(130), SLR(130), -// * U(131) -// INTEGER H, Q, R, S, T -// EQUIVALENCE (LZ,RH), (NZ,CH) -// C -// C THIS SUBROUTINE SOLVES THE SQUARE ASSIGNMENT PROBLEM -// C THE MEANING OF THE INPUT PARAMETERS IS -// C N = NUMBER OF ROWS AND COLUMNS OF THE COST MATRIX, WITH -// C THE CURRENT DIMENSIONS THE MAXIMUM VALUE OF N IS 130 -// C A(I,J) = ELEMENT IN ROW I AND COLUMN J OF THE COST MATRIX -// C ( AT THE END OF COMPUTATION THE ELEMENTS OF A ARE CHANGED) -// C THE MEANING OF THE OUTPUT PARAMETERS IS -// C C(J) = ROW ASSIGNED TO COLUMN J (J=1,N) -// C T = COST OF THE OPTIMAL ASSIGNMENT -// C ALL PARAMETERS ARE INTEGER -// C THE MEANING OF THE LOCAL VARIABLES IS -// C A(I,J) = ELEMENT OF THE COST MATRIX IF A(I,J) IS POSITIVE, -// C COLUMN OF THE UNASSIGNED ZERO FOLLOWING IN ROW I -// C (I=1,N) THE UNASSIGNED ZERO OF COLUMN J (J=1,N) -// C IF A(I,J) IS NOT POSITIVE -// C A(I,N+1) = COLUMN OF THE FIRST UNASSIGNED ZERO OF ROW I -// C (I=1,N) -// C CH(I) = COLUMN OF THE NEXT UNEXPLORED AND UNASSIGNED ZERO -// C OF ROW I (I=1,N) -// C LC(J) = LABEL OF COLUMN J (J=1,N) -// C LR(I) = LABEL OF ROW I (I=1,N) -// C LZ(I) = COLUMN OF THE LAST UNASSIGNED ZERO OF ROW I(I=1,N) -// C NZ(I) = COLUMN OF THE NEXT UNASSIGNED ZERO OF ROW I(I=1,N) -// C RH(I) = UNEXPLORED ROW FOLLOWING THE UNEXPLORED ROW I -// C (I=1,N) -// C RH(N+1) = FIRST UNEXPLORED ROW -// C SLC(K) = K-TH ELEMENT CONTAINED IN THE SET OF THE LABELLED -// C COLUMNS -// C SLR(K) = K-TH ELEMENT CONTAINED IN THE SET OF THE LABELLED -// C ROWS -// C U(I) = UNASSIGNED ROW FOLLOWING THE UNASSIGNED ROW I -// C (I=1,N) -// C U(N+1) = FIRST UNASSIGNED ROW -// C -// C THE VECTORS C,CH,LC,LR,LZ,NZ,SLC,SLR MUST BE DIMENSIONED -// C AT LEAST AT (N), THE VECTORS RH,U AT LEAST AT (N+1), -// C THE MATRIX A AT LEAST AT (N,N+1) -// C -// C INITIALIZATION - - int KSLC = -1; - int L = -1; - int I = -1; - int M = -1; - int J = -1; - int K = -1; - int LJ = -1; - int LM = -1; - int KSLR = -1; - int NL = -1; - int NM = -1; - - //N = N-1; - //NP1 = NP1-1; - // NP1 = N+1 - - for (J=1; J<=N; J++) { - // DO 10 J=1,N - C[J] = 0; - LZ[J] = 0; - NZ[J] = 0; - U[J] = 0; - }//for (int J=0; J<N; J++) - //10 CONTINUE - U[NP1] = 0; - T = 0; - //C REDUCTION OF THE INITIAL COST MATRIX - - for (J=1; J<=N; J++) { - // DO 40 J=1,N - S = A[1][J]; - for (L=2; L<=N; L++) { - //DO 20 L=2,N - if (A[L][J] < S) S = A[L][J]; - //IF ( A(L,J) .LT. S ) S = A(L,J) - }//for (int L=1; L<N; L++) - //20 CONTINUE - T = T+S; - for (I=1; I<=N; I++) { - //DO 30 I=1,N - A[I][J] = A[I][J]-S; - }//for (int I=0; I<N; I++) - //30 CONTINUE - - }//for (int J=0; J<N; J++) - // 40 CONTINUE - for (I=1; I<=N; I++) { - //DO 70 I=1,N - Q = A[I][1]; - for (L=2; L<=N; L++) { - //DO 50 L=2,N - //System.out.println("I="+I+" L="+L); - if (A[I][L] < Q) Q = A[I][L]; - //IF ( A(I,L) .LT. Q ) Q = A(I,L) - }//for (int L=1; L<N; L++) - //50 CONTINUE - T = T+Q; - L = NP1; - for (J=1; J<=N; J++) { - //DO 60 J=1,N - A[I][J] = A[I][J]-Q; - if (A[I][J] != 0) continue; - //IF ( A[I,J] .NE. 0 ) GO TO 60 - A[I][L] = -J; - L = J; - }//for (int J=0; J<N; J++) - //60 CONTINUE - }//for (int I=0; I<N; N++) - //70 CONTINUE - //C CHOICE OF THE INITIAL SOLUTION - - - K = NP1; - for140: - for (I=1; I<=N; I++) { - // DO 140 I=1,N - LJ = NP1; - J = -A[I][NP1]; - - do { - if (C[J] == 0) { - // 80 IF ( C(J) .EQ. 0 ) { GO TO 130 - - C[J] = I; - A[I][LJ] = A[I][J]; - NZ[I] = -A[I][J]; - LZ[I] = LJ; - A[I][J] = 0; - continue for140; //break?? - } - - LJ = J; - J = -A[I][J]; - - } while (J != 0); - // IF ( J .NE. 0 ) GO TO 80 - LJ = NP1; - J = -A[I][NP1]; - - do90: - do { - R = C[J]; - LM = LZ[R]; - M = NZ[R]; - - while100goto120 = false; - while100: - while (true) { - if (M == 0) break while100; - // 100 IF ( M .EQ. 0 ) GO TO 110 - if (C[M] == 0){ - while100goto120 = true; - break do90; - } - // IF ( C(M) .EQ. 0 ) GO TO 120// M != 0 && C[m] == 0 - LM = M; - M = -A[R][M]; - } - // GO TO 100 - - //110 - LJ = J; - J = -A[I][J]; - } while (J != 0); - // IF ( J .NE. 0 ) GO TO 90 - - if ( !while100goto120 ) { - U[K] = I; - K = I; - continue for140; - // GO TO 140 - } - // 120 - while100goto120 = false; - NZ[R] = -A[R][M]; - LZ[R] = J; - A[R][LM] = -J; - A[R][J] = A[R][M]; - A[R][M] = 0; - C[M] = R; - - //130 - C[J] = I; - A[I][LJ] = A[I][J]; - NZ[I] = -A[I][J]; - LZ[I] = LJ; - A[I][J] = 0; - - - // 140 CONTINUE - } - //C RESEARCH OF A NEW ASSIGNMENT - while392: - while (true) { - if (U[NP1] == 0) return T; - // 150 IF ( U(NP1) .EQ. 0 ) RETURN - - for (I=1; I<=N; I++) { - // DO 160 I=1,N - CH[I] = 0; - LC[I] = 0; - LR[I] = 0; - RH[I] = 0; - } - // 160 CONTINUE - RH[NP1] = -1; - KSLC = 0; - KSLR = 1; - R = U[NP1]; - //System.out.println("R: "+R); - LR[R] = -1; - SLR[1] = R; - - boolean goto190 = false; - while360: - while(true) { - do350: - do { - //System.out.println("R: "+R+" NP1: "+NP1); - if (goto190 || A[R][NP1] != 0) { - // IF ( A(R,NP1) .EQ. 0 ) GO TO 220 - - - do200: - do { - if (!goto190) { - // 170 - L = -A[R][NP1]; - - if (A[R][L] != 0) { - // IF ( A(R,L) .EQ. 0 ) GO TO 180 - if (RH[R] == 0) { - // IF ( RH(R) .NE. 0 ) GO TO 180 - RH[R] = RH[NP1]; - CH[R] = -A[R][L]; - RH[NP1] = R; - } - } - }// if (!goto190) - //boolean goto210 = false; - while190: - while (true) { - if (!goto190) { - if (LC[L] ==0) break while190; - //180 IF ( LC(L) .EQ. 0 ) GO TO 200 - - if (RH[R] == 0) { - break do200; - // goto210 = true; - //break; - } - // IF ( RH(R) .EQ. 0 ) GO TO 210 - }// if (!goto190) - goto190 = false; - // 190 - L = CH[R]; - CH[R] = -A[R][L]; - if (A[R][L] != 0) continue while190; - //IF ( A(R,L) .NE. 0 ) GO TO 180 - RH[NP1] = RH[R]; - RH[R] = 0; - - //GO TO 180 - - }//end while190 - - //if (!goto210) { - //200 - LC[L] = R; - - if (C[L] == 0) break while360; - //IF ( C(L) .EQ. 0 ) GO TO 360 - - KSLC = KSLC+1; - SLC[KSLC] = L; - R = C[L]; - LR[R] = L; - KSLR = KSLR+1; - SLR[KSLR] = R; - //} - } while (A[R][NP1] != 0); //do200 - // IF ( A(R,NP1) .NE. 0 ) GO TO 170 - //}// if (!goto210) - // goto210 = false; - // 210 CONTINUE - - if (RH[NP1] > 0) break do350; - //IF ( RH(NP1) .GT. 0 ) GO TO 350 - - }// if (A[R,L] != 0) - //C REDUCTION OF THE CURRENT COST MATRIX - // 220 - H = Integer.MAX_VALUE; - - for240: - for (J=1; J<=N; J++) { - // DO 240 J=1,N - - if (LC[J] != 0) continue for240; - // IF ( LC(J) .NE. 0 ) GO TO 240 - - for (K=1; K<=KSLR; K++) { - // DO 230 K=1,KSLR - I = SLR[K]; - if (A[I][J] < H) H = A[I][J]; - // IF ( A(I,J) .LT. H ) H = A(I,J) - }// for (int K=0; K<KSLR; K++) - // 230 CONTINUE - - }// for (int J; J<N; J++) - // 240 CONTINUE - - T = T+H; - - for290: - for (J=1; J<=N; J++) { - // DO 290 J=1,N - - if (LC[J] != 0 ) continue for290; - // IF ( LC(J) .NE. 0 ) GO TO 290 - - for280: - for (K=1; K<=KSLR; K++) { - // DO 280 K=1,KSLR - I = SLR[K]; - A[I][J] = A[I][J]-H; - if (A[I][J] != 0) continue for280; - // IF ( A(I,J) .NE. 0 ) GO TO 280 - - if (RH[I] == 0) { - // IF ( RH(I) .NE. 0 ) GO TO 250 - RH[I] = RH[NP1]; - CH[I] = J; - RH[NP1] = I; - }// if (RH[I] == 0) - //250 - L = NP1; - //260 - while (true) { - NL = -A[I][L]; - if (NL == 0) break; - // IF ( NL .EQ. 0 ) GO TO 270 - L = NL; - }// while (true) - // GO TO 260 - //270 - A[I][L] = -J; - - }// for (int K=0; K<KSLR; K++) - // 280 CONTINUE - - }// for (int J=0; J<N; J++) - // 290 CONTINUE - - if (KSLC != 0) { - //IF ( KSLC .EQ. 0 ) GO TO 350 - - for340: - for (I=1; I<=N; I++) { - // DO 340 I=1,N - - if (LR[I] != 0) continue for340; - //IF ( LR(I) .NE. 0 ) GO TO 340 - - for330: - for (K=1; K<=KSLC; K++) { - //DO 330 K=1,KSLC - J = SLC[K]; - - boolean enter_if = false; - if (A[I][J] <= 0) { - //IF ( A(I,J) .GT. 0 ) GO TO 320 - L = NP1; - //300 - while (true) { - NL = - A[I][L]; - if (NL == J) break; - //IF ( NL .EQ. J ) GO TO 310 - L = NL; - }//while (true) - //GO TO 300 - //310 - A[I][L] = A[I][J]; - A[I][J] = H; - //GO TO 330 - enter_if = true; - }//if (A[I,J] <=0) - if (!enter_if) { - //320 - A[I][J] = A[I][J]+H; - } - }//for (int K=0; K<KSLC; K++) - // 330 CONTINUE - }//for (int I=0; I<N; I++) - // 340 CONTINUE - }// if (KSLC != 0) - - } while (false);//do350 - //350 - R = RH[NP1]; - //System.out.println("R: "+R+" at 350"); - goto190 = true; - }//while360 - // GO TO 190 - //C ASSIGNMENT OF A NEW ROW - while389: - while (true) { - //360 - C[L] = R; - M = NP1; - //370 - while (true) { - NM = -A[R][M]; - if (NM == L) break; - // IF ( NM .EQ. L ) GO TO 380 - M = NM; - }//while (true) - // GO TO 370 - //380 - A[R][M] = A[R][L]; - A[R][L] = 0; - if (LR[R] < 0) break while389; - // IF ( LR(R) .LT. 0 ) GO TO 390 - L = LR[R]; - A[R][L] = A[R][NP1]; - A[R][NP1] = -L; - R = LC[L]; - }//while389 - // GO TO 360 - //390 - U[NP1] = U[R]; - U[R] = 0; - } - // GO TO 150 - //END - } - -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/IdMap.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/IdMap.java deleted file mode 100644 index 62bb23c62..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/IdMap.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.ArrayList; -import java.util.Vector; - -/** This class is used to represent a id mapping scheme in the XML Compare preference page - */ -public class IdMap { - - private String fName; - private boolean fInternal; - private Vector fMappings; - private String fExtension; - private ArrayList fOrdered;//contains Mapping elements for list of ordered entries (the children of these elements will be compared in ordered fashion) - - /** - * Creates an IdMap which represents an Id Mapping Scheme - * @param internal true if the IdMap is internal - */ - public IdMap(boolean internal) { - this("", internal); //$NON-NLS-1$ - } - - /** - * Creates an IdMap which represents an Id Mapping Scheme - * @param name The name of the mapping, as in fIdMaps/fIdMapsInternal HashMaps and fOrderedElements/fOrderedElementsInternal HashMaps - * @param internal true if the IdMap is internal - */ - public IdMap(String name, boolean internal) { - this(name, internal, new Vector()); - } - - /** - * Creates an IdMap which represents an Id Mapping Scheme - * @param name The name of the mapping, as in fIdMaps/fIdMapsInternal HashMaps and fOrderedElements/fOrderedElementsInternal HashMaps - * @param internal true if the IdMap is internal - * @param mappings Vector of Mapping elements which represent the id mappings of this id mapping scheme - */ - public IdMap(String name, boolean internal, Vector mappings) { - this(name, internal, mappings, ""); //$NON-NLS-1$ - } - - /** - * Creates an IdMap which represents an Id Mapping Scheme. - * @param name The name of the mapping, as in fIdMaps/fIdMapsInternal HashMaps and fOrderedElements/fOrderedElementsInternal HashMaps. - * @param internal true if the IdMap is internal. - * @param mappings Vector of Mapping elements which represent the id mappings of this id mapping scheme. - * @param extension Optional extension to be associated with this id mapping scheme. - */ - public IdMap(String name, boolean internal, Vector mappings, String extension) { - this(name, internal, mappings, extension, null); - } - - /** - * Creates an IdMap which represents an Id Mapping Scheme. - * @param name The name of the mapping, as in fIdMaps/fIdMapsInternal HashMaps and fOrderedElements/fOrderedElementsInternal HashMaps. - * @param internal true if the IdMap is internal. - * @param mappings Vector of Mapping elements which represent the id mappings of this id mapping scheme. - * @param extension Optional extension to be associated with this id mapping scheme. - * @param ordered Optional ArrayList of Mapping elements representing ordered entries. - */ - public IdMap(String name, boolean internal, Vector mappings, String extension, ArrayList ordered) { - fName = name; - fInternal = internal; - fMappings = mappings; - fExtension= extension.toLowerCase(); - fOrdered= ordered; - } - - /* - * @see Object#equals(Object) - */ - public boolean equals(Object object) { - if (!(object instanceof IdMap)) - return false; - - IdMap idmap= (IdMap) object; - - if (idmap == this) - return true; - - return - idmap.getName().equals(fName) && - idmap.getMappings().equals(fMappings); - } - - /* - * @see Object#hashCode() - */ - public int hashCode() { - return fName.hashCode() ^ fMappings.hashCode(); - } - - public void setName(String name) { - fName = name; - } - - public String getName() { - return fName; - } - - public void setMappings(Vector mappings) { - fMappings = mappings; - } - - public Vector getMappings() { - return fMappings; - } - - public void setInternal(boolean bool) { - fInternal = bool; - } - - public boolean isInternal() { - return fInternal; - } - - public void setExtension(String extension) { - fExtension= extension; - } - - public String getExtension() { - return fExtension; - } - public void setOrdered(ArrayList ordered) { - fOrdered= ordered; - } - public ArrayList getOrdered() { - return fOrdered; - } - -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Mapping.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Mapping.java deleted file mode 100644 index da2515562..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Mapping.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -/** This class is used to represent a particular id mapping or ordered entry in the XML Compare preference page - */ -public class Mapping { - - private String fElement; - private String fSignature; - private String fIdAttribute; - - public Mapping() { - this("", "", ""); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - } - - public Mapping(String element, String signature) { - this(element, signature, ""); //$NON-NLS-1$ - } - - public Mapping(String element, String signature, String idattribute) { - fElement = element; - fSignature = signature; - fIdAttribute = idattribute; - } - - /* - * @see Object#equals(Object) - */ - public boolean equals(Object object) { - if (!(object instanceof Mapping)) - return false; - - Mapping mapping= (Mapping) object; - - if (mapping == this) - return true; - - return - mapping.fElement.equals(fElement) && - mapping.fSignature.equals(fSignature) && - mapping.fIdAttribute.equals(fIdAttribute); - } - - /* - * @see Object#hashCode() - */ - public int hashCode() { - return fElement.hashCode() ^ fSignature.hashCode(); - } - - public void setElement(String element) { - fElement = element; - } - public String getElement() { - return fElement; - } - - public void setSignature(String signature) { - fSignature = signature; - } - public String getSignature() { - return fSignature; - } - - public void setIdAttribute(String idattribute) { - fIdAttribute = idattribute; - } - public String getIdAttribute() { - return fIdAttribute; - } - - public String getKey() { - return getKey(fSignature, fElement); - } - - public static String getKey(String signature, String element) { - if (signature == "") //$NON-NLS-1$ - return XMLStructureCreator.ROOT_ID + XMLStructureCreator.SIGN_SEPARATOR + element + XMLStructureCreator.SIGN_SEPARATOR; - else - return XMLStructureCreator.ROOT_ID + XMLStructureCreator.SIGN_SEPARATOR + signature + XMLStructureCreator.SIGN_SEPARATOR + element + XMLStructureCreator.SIGN_SEPARATOR; - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/OrderedMatching.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/OrderedMatching.java deleted file mode 100644 index 6d4849fb1..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/OrderedMatching.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.core.runtime.IProgressMonitor; - -public class OrderedMatching extends AbstractMatching { - - public OrderedMatching() { - super(); - } - - protected int orderedMath(XMLNode x, XMLNode y) { - //assumes x and y have children - Object[] xc= x.getChildren(); - Object[] yc= y.getChildren(); - - ArrayList xc_elementsAL= new ArrayList(); - ArrayList xc_attrsAL= new ArrayList(); - - ArrayList yc_elementsAL= new ArrayList(); - ArrayList yc_attrsAL= new ArrayList(); - - //find attributes and elements and put them in xc_elementsAL and xc_attrsAL, respectively - for (int i= 0; i < xc.length; i++) { - XMLNode x_i= (XMLNode) xc[i]; - if (x_i.getXMLType().equals(XMLStructureCreator.TYPE_ELEMENT)) { - xc_elementsAL.add(x_i); - } else if ( - x_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) { - xc_attrsAL.add(x_i); - } - } - - //do the same for yc - for (int i= 0; i < yc.length; i++) { - XMLNode y_i= (XMLNode) yc[i]; - if (y_i.getXMLType().equals(XMLStructureCreator.TYPE_ELEMENT)) { - yc_elementsAL.add(y_i); - } else if ( - y_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) { - yc_attrsAL.add(y_i); - } - } - - Object[] xc_elements= xc_elementsAL.toArray(); - Object[] yc_elements= yc_elementsAL.toArray(); - - ArrayList DTMatching= new ArrayList(); - // Matching to be added to Entry in fDT_Matchings - int distance= 0; //distance to be added to entry in fDT - - // perform unordered matching on attributes - // this updates fDT and fDT_Matchings - if (xc_attrsAL.size() > 0 || yc_attrsAL.size() > 0) { - if (xc_attrsAL.size() == 0) - distance += yc_attrsAL.size(); - else if (yc_attrsAL.size() == 0) - distance += xc_attrsAL.size(); - else { - //unorderedMatch(x, y, xc_attrs, yc_attrs); - // distance += fDT[indexOfLN(x)][indexOfRN(y)]; - // DTMatching= fDT_Matchings[indexOfLN(x)][indexOfRN(y)]; - distance= handleAttributes(xc_attrsAL, yc_attrsAL, DTMatching); - } - } - - //perform ordered matching on element children, i.e. number them in order of appearance - - /* start new */ - distance= - handleRangeDifferencer( - xc_elements, - yc_elements, - DTMatching, - distance); - /* end new */ - - /* start: Naive ordered compare /* - // int minlength= (xc_elements.length > yc_elements.length)?yc_elements.length:xc_elements.length; - // for (int i= 0; i < minlength; i++) { - // distance += dist((XMLNode) xc_elements[i], (XMLNode) yc_elements[i]); - // DTMatching.add(new Match( (XMLNode)xc_elements[i], (XMLNode)yc_elements[i])); - // } - // if (xc_elements.length > yc_elements.length) { - // for (int i= minlength; i < xc_elements.length; i++) { - // distance += countNodes((XMLNode) xc_elements[i]); - // } - // } else if (xc_elements.length < yc_elements.length) { - // for (int i= minlength; i < yc_elements.length; i++) { - // distance += countNodes((XMLNode) yc_elements[i]); - // } - // } - /* end: Naive ordered compare */ - - fDT[indexOfLN(x)][indexOfRN(y)]= distance; - fDT_Matchings[indexOfLN(x)][indexOfRN(y)]= DTMatching; - return distance; - - } - - /* matches two trees according to paper "X-Diff", p. 16 */ - public void match( - XMLNode LeftTree, - XMLNode RightTree, - boolean rightTreeIsAncestor, - IProgressMonitor monitor) - throws InterruptedException { - - fNLeft= new Vector(); - //numbering LeftTree: Mapping nodes in LeftTree to numbers to be used as array indexes - fNRight= new Vector(); - //numbering RightTree: Mapping nodes in RightTree to numbers to be used as array indexes - numberNodes(LeftTree, fNLeft); - numberNodes(RightTree, fNRight); - fDT= new int[fNLeft.size()][fNRight.size()]; - fDT_Matchings= new ArrayList[fNLeft.size()][fNRight.size()]; - for (int i= 0; i < fDT.length; i++) { - fDT[i]= new int[fNRight.size()]; - for (int j= 0; j < fDT[0].length; j++) { - fDT[i][j]= NO_ENTRY; - } - } - - dist(LeftTree, RightTree); - // /* mark matchings on LeftTree and RightTree */ - fMatches= new Vector(); - if (!LeftTree.getSignature().equals(RightTree.getSignature())) { - //matching is empty - } else { - fMatches.add(new Match(LeftTree, RightTree)); - for (int i_M= 0; i_M < fMatches.size(); i_M++) { - Match m= (Match) fMatches.elementAt(i_M); - if (!isLeaf(m.fx) && !isLeaf(m.fy)) { - // if (fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ] == null) - // System.out.println("Error: ID not unique for " + m.fx.getId()); - // else - // fMatches.addAll(fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ]); - if (fDT_Matchings[indexOfLN(m.fx)][indexOfRN(m.fy)] - != null) - fMatches.addAll( - fDT_Matchings[indexOfLN(m.fx)][indexOfRN(m.fy)]); - } - } - } - //end of Step2 - /* Renumber Id of Nodes to follow Matches. Or for ancestor, copy over Id to ancestor */ - if (rightTreeIsAncestor) { - for (ListIterator it_M= fMatches.listIterator(); it_M.hasNext();) { - Match m= (Match) it_M.next(); - if (m.fx != null && m.fy != null) - m.fy.setId(m.fx.getId()); - } - } else { - int newId= 0; - for (ListIterator it_M= fMatches.listIterator(); - it_M.hasNext(); - newId++) { - Match m= (Match) it_M.next(); - if (m.fx != null) - m.fx.setId(Integer.toString(newId)); - if (m.fy != null) - m.fy.setId(Integer.toString(newId)); - // System.out.println("Matching: "+ ((m.fx != null)?m.fx.getOrigId():"null")+" -> "+((m.fx != null)?m.fx.getId():"null")+" , "+((m.fy != null)?m.fy.getOrigId():"null")+" -> "+((m.fy != null)?m.fy.getId():"null")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - } - //if (monitor != null) monitor.done(); - } - - public int handleAttributes( - ArrayList xc_attrs, - ArrayList yc_attrs, - ArrayList DTMatching) { - int distance= 0; - x_for : for ( - Iterator iter_xc= xc_attrs.iterator(); iter_xc.hasNext();) { - XMLNode x_attr= (XMLNode) iter_xc.next(); - String x_attr_name= x_attr.getName(); - for (Iterator iter_yc= yc_attrs.iterator(); iter_yc.hasNext();) { - XMLNode y_attr= (XMLNode) iter_yc.next(); - if (y_attr.getName().equals(x_attr_name)) { - if (!y_attr.getValue().equals(x_attr.getValue())) - distance += 1; - DTMatching.add(new Match(x_attr, y_attr)); - yc_attrs.remove(y_attr); - continue x_for; - } - } - DTMatching.add(new Match(x_attr, null)); - distance += 1; - } - - for (Iterator iter_yc= yc_attrs.iterator(); iter_yc.hasNext();) { - DTMatching.add(new Match(null, (XMLNode) iter_yc.next())); - distance += 1; - } - - return distance; - } - - protected int handleXandYnotLeaves(XMLNode x, XMLNode y) { - /* handle entries as ordered*/ - return orderedMath(x, y); - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java deleted file mode 100644 index f65bd5155..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.DragSource; -import org.eclipse.swt.dnd.DropTarget; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Caret; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Widget; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.util.Assert; - -/** - * Utility class to simplify access to some SWT resources. - */ -public class SWTUtil { - - /** - * Returns the standard display to be used. The method first checks, if - * the thread calling this method has an associated disaply. If so, this - * display is returned. Otherwise the method returns the default display. - */ - public static Display getStandardDisplay() { - Display display; - display= Display.getCurrent(); - if (display == null) - display= Display.getDefault(); - return display; - } - - /** - * Returns the shell for the given widget. If the widget doesn't represent - * a SWT object that manage a shell, <code>null</code> is returned. - * - * @return the shell for the given widget - */ - public static Shell getShell(Widget widget) { - if (widget instanceof Control) - return ((Control)widget).getShell(); - if (widget instanceof Caret) - return ((Caret)widget).getParent().getShell(); - if (widget instanceof DragSource) - return ((DragSource)widget).getControl().getShell(); - if (widget instanceof DropTarget) - return ((DropTarget)widget).getControl().getShell(); - if (widget instanceof Menu) - return ((Menu)widget).getParent().getShell(); - if (widget instanceof ScrollBar) - return ((ScrollBar)widget).getParent().getShell(); - - return null; - } - - - private static double getVerticalDialogUnitSize(Control control) { - GC gc= new GC(control); - try { - int height = gc.getFontMetrics().getHeight(); - return height * 0.125; - } finally { - gc.dispose(); - } - } - - private static double getHorizontalDialogUnitSize(Control control) { - GC gc= new GC(control); - try { - int averageWidth= gc.getFontMetrics().getAverageCharWidth(); - return averageWidth * 0.25; - } finally { - gc.dispose(); - } - } - - - /** - * @see DialogPage#convertHeightInCharsToPixels - */ - public static int convertHeightInCharsToPixels(int chars, Control control) { - return convertVerticalDLUsToPixels(chars * 8, control); - } - - /** - * @see DialogPage#convertHorizontalDLUsToPixels - */ - public static int convertHorizontalDLUsToPixels(int dlus, Control control) { - return (int)Math.round(dlus * getHorizontalDialogUnitSize(control)); - } - - /** - * @see DialogPage#convertVerticalDLUsToPixels - */ - public static int convertVerticalDLUsToPixels(int dlus, Control control) { - return (int)Math.round(dlus * getVerticalDialogUnitSize(control)); - } - - /** - * @see DialogPage#convertWidthInCharsToPixels - */ - public static int convertWidthInCharsToPixels(int chars, Control control) { - return convertHorizontalDLUsToPixels(chars * 4, control); - } - - /** - * Returns a width hint for a button control. - */ - public static int getButtonWidthHint(Button button) { - int widthHint= convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH, button); - return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); - } - - /** - * Returns a height hint for a button control. - */ - public static int getButtonHeigthHint(Button button) { - return convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT, button); - } - - /** - * Sets width and height hint for the button control. - * <b>Note:</b> This is a NOP if the button's layout data is not - * an instance of <code>GridData</code>. - * - * @param the button for which to set the dimension hint - */ - public static void setButtonDimensionHint(Button button) { - Assert.isNotNull(button); - Object gd= button.getLayoutData(); - if (gd instanceof GridData) { - ((GridData)gd).heightHint= getButtonHeigthHint(button); - ((GridData)gd).widthHint= getButtonWidthHint(button); - } - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SelectMatcherAction.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SelectMatcherAction.java deleted file mode 100644 index f9f72ca50..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SelectMatcherAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import org.eclipse.jface.action.Action; - -class SelectMatcherAction extends Action { - - private XMLStructureViewer fViewer; - private String fDesc; - - public SelectMatcherAction(String desc, XMLStructureViewer viewer) { - fViewer= viewer; - fDesc= desc; - setText(fDesc); - setToolTipText(fDesc); - } - - public void run() { - ((XMLStructureCreator) fViewer.getStructureCreator()).setIdMap(fDesc); - fViewer.contentChanged(); - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLChildren.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLChildren.java deleted file mode 100644 index c823f868f..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLChildren.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.HashMap; - -import org.eclipse.jface.text.IDocument; - -/** XMLNode that has children elements */ -public class XMLChildren extends XMLNode { - - public int children; // counts the number of children - public HashMap childElements; // maps the name of XML child elements to their # of occurence - - public XMLChildren(String XMLType, String id, String value, String signature, IDocument doc, int start, int length) { - super(XMLType, id, value, signature, doc, start, length); - children= 0; - childElements = new HashMap(); - } -} - diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareAddIdMapDialog.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareAddIdMapDialog.java deleted file mode 100644 index 956e114b3..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareAddIdMapDialog.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.text.MessageFormat; -import java.util.*; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.*; - -import org.eclipse.compare.examples.xml.ui.StatusDialog; -import org.eclipse.compare.examples.xml.ui.StatusInfo; - -/** - * This class is used to add or edit an ID Mapping Scheme - */ -public class XMLCompareAddIdMapDialog extends StatusDialog { - - private IdMap fIdMap; - private HashMap fIdMaps; - private HashMap fIdMapsInternal; - private HashMap fIdExtensionToName; - private boolean fEdit; - - private Text fIdMapText; - private Text fIdMapExtText; - - public XMLCompareAddIdMapDialog(Shell parent, IdMap idmap, HashMap idmaps, HashMap idmapsInternal, HashMap idextensiontoname, boolean edit) { - super(parent); - - fEdit= edit; - if (fEdit) - setTitle(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.editTitle")); //$NON-NLS-1$ - else - setTitle(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.newTitle")); //$NON-NLS-1$ - - fIdMap= idmap; - fIdMaps= idmaps; - fIdMapsInternal= idmapsInternal; - fIdExtensionToName= idextensiontoname; - } - - /** - * Creates and returns the contents of the upper part - * of the dialog (above the button bar). - * - * Subclasses should override. - * - * @param the parent composite to contain the dialog area - * @return the dialog area control - */ - protected Control createDialogArea(Composite ancestor) { - Composite composite= (Composite) super.createDialogArea(ancestor); - - Composite inner= new Composite(composite, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - inner.setLayout(layout); - inner.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.label")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fIdMapText= new Text(inner, SWT.BORDER); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = convertWidthInCharsToPixels(30); - fIdMapText.setLayoutData(data); - fIdMapText.setText(fIdMap.getName()); - fIdMapText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.extlabel")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fIdMapExtText= new Text(inner, SWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = convertWidthInCharsToPixels(30); - fIdMapExtText.setLayoutData(data); - fIdMapExtText.setText(fIdMap.getExtension()); - fIdMapExtText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - - fIdMapText.setFocus(); - - return composite; - } - - /** - * Validate user input - */ - private void doValidation() { - StatusInfo status= new StatusInfo(); - String newText= fIdMapText.getText(); - if (newText.length() == 0) - status.setError(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.error.noname")); //$NON-NLS-1$ - else if (XMLComparePreferencePage.containsInvalidCharacters(newText)) - status.setError(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.error.invalidname")); //$NON-NLS-1$ - else if ( (!fEdit && (fIdMaps.containsKey(newText) || fIdMapsInternal.containsKey(newText)) ) - || (fEdit && !newText.equals(fIdMap.getName()) && (fIdMaps.containsKey(newText) || fIdMapsInternal.containsKey(newText)) ) - ) - status.setError(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.error.idmapExists")); //$NON-NLS-1$ - newText= fIdMapExtText.getText().toLowerCase(); - if (newText.length() > 0) { - if (newText.indexOf(".") > -1) //$NON-NLS-1$ - status.setError(XMLCompareMessages.getString("XMLCompareAddIdMapDialog.error.extfullstop")); //$NON-NLS-1$ - else if (fIdExtensionToName.containsKey(newText) && !fIdExtensionToName.get(newText).equals(fIdMap.getName())) - status.setError(MessageFormat.format("{0} {1}",new String[] {XMLCompareMessages.getString("XMLCompareAddIdMapDialog.error.extExists"),(String)fIdExtensionToName.get(newText)})); //$NON-NLS-2$ //$NON-NLS-1$ - } - updateStatus(status); - } - - /** - * Notifies that the ok button of this dialog has been pressed. - */ - protected void okPressed() { - fIdMap.setName(fIdMapText.getText()); - fIdMap.setExtension(fIdMapExtText.getText().toLowerCase()); - super.okPressed(); - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditCopyIdMapDialog.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditCopyIdMapDialog.java deleted file mode 100644 index d9d3a3ebe..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditCopyIdMapDialog.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.HashMap; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.*; - -import org.eclipse.compare.examples.xml.ui.StatusDialog; -import org.eclipse.compare.examples.xml.ui.StatusInfo; - -/** - * This class is used to create an editable ID Mapping Scheme from an internal ID Mappping Scheme - */ -public class XMLCompareEditCopyIdMapDialog extends StatusDialog { - - private HashMap fIdMaps; - private HashMap fIdMapsInternal; - - private Text fIdMapText; - private String fResult; - - /** - * Constructs a new edit copy mapping dialog. - */ - public XMLCompareEditCopyIdMapDialog(Shell parent, IdMap idmap, HashMap idmaps, HashMap idmapsInternal) { - super(parent); - - setTitle(XMLCompareMessages.getString("XMLCompareEditCopyIdMapDialog.title")); //$NON-NLS-1$ - - fIdMaps= idmaps; - fIdMapsInternal= idmapsInternal; - } - - public String getResult() { - return fResult; - } - - /** - * Creates and returns the contents of the upper part - * of the dialog (above the button bar). - * - * Subclasses should override. - * - * @param the parent composite to contain the dialog area - * @return the dialog area control - */ - protected Control createDialogArea(Composite ancestor) { - Composite composite= (Composite) super.createDialogArea(ancestor); - - Label comment= new Label(composite, SWT.NONE); - comment.setText(XMLCompareMessages.getString("XMLCompareEditCopyIdMapDialog.comment")); //$NON-NLS-1$ - GridData data= new GridData(); - data.horizontalAlignment= GridData.FILL; - data.verticalAlignment= GridData.BEGINNING; - comment.setLayoutData(data); - - Composite inner= new Composite(composite, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - inner.setLayout(layout); - inner.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareEditCopyIdMapDialog.label")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fIdMapText= new Text(inner, SWT.BORDER); - fIdMapText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fIdMapText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - fIdMapText.setFocus(); - - return composite; - } - - /** - * Validate user input - */ - private void doValidation() { - StatusInfo status= new StatusInfo(); - String newText= fIdMapText.getText(); - if (newText.length() == 0) - status.setError(XMLCompareMessages.getString("XMLCompareEditCopyIdMapDialog.error.noname")); //$NON-NLS-1$ - else if (XMLComparePreferencePage.containsInvalidCharacters(newText)) - status.setError(XMLCompareMessages.getString("XMLCompareEditCopyIdMapDialog.error.invalidname")); //$NON-NLS-1$ - else if (fIdMaps.containsKey(newText) || fIdMapsInternal.containsKey(newText)) - status.setError(XMLCompareMessages.getString("XMLCompareEditCopyIdMapDialog.error.nameExists")); //$NON-NLS-1$ - updateStatus(status); - } - - /** - * Notifies that the ok button of this dialog has been pressed. - */ - protected void okPressed() { - fResult= fIdMapText.getText(); - super.okPressed(); - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditMappingDialog.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditMappingDialog.java deleted file mode 100644 index 69fb73838..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditMappingDialog.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.HashMap; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.*; - -import org.eclipse.compare.examples.xml.ui.StatusDialog; -import org.eclipse.compare.examples.xml.ui.StatusInfo; - -/** - * This class is used to add or edit a particular ID Mapping - */ -public class XMLCompareEditMappingDialog extends StatusDialog { - - private Mapping fMapping; - private HashMap fIdmapHM; - private boolean fEdit; - - private Text fElementText; - private Text fSignatureText; - private Text fIdAttributeText; - - private Button fIdTypeAttributeButton; - private Button fIdTypeChildBodyButton; - - /** - * Constructs a new edit mapping dialog. - */ - public XMLCompareEditMappingDialog(Shell parent, Mapping mapping, HashMap idmapHM, boolean edit) { - super(parent); - - int shellStyle= getShellStyle(); - setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE); - - - fEdit= edit; - if (fEdit) - setTitle(XMLCompareMessages.getString("XMLCompareEditMappingDialog.editTitle")); //$NON-NLS-1$ - else - setTitle(XMLCompareMessages.getString("XMLCompareEditMappingDialog.newTitle")); //$NON-NLS-1$ - - fMapping= mapping; - fIdmapHM= idmapHM; - } - - /** - * Creates and returns the contents of the upper part - * of the dialog (above the button bar). - * - * Subclasses should override. - * - * @param the parent composite to contain the dialog area - * @return the dialog area control - */ - protected Control createDialogArea(Composite ancestor) { - Composite composite= (Composite) super.createDialogArea(ancestor); - - Composite inner= new Composite(composite, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - inner.setLayout(layout); - inner.setLayoutData(new GridData(GridData.FILL_BOTH)); - - //Element - Label label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.element")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fElementText= new Text(inner, SWT.BORDER); - fElementText.setText(fMapping.getElement()); - fElementText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fElementText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - //Signature - label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.signature")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fSignatureText= new Text(inner, SWT.BORDER); - fSignatureText.setText(fMapping.getSignature()); - GridData data= new GridData(GridData.FILL_HORIZONTAL); - data.widthHint= convertWidthInCharsToPixels(50); - fSignatureText.setLayoutData(data); - fSignatureText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - //Id Attribute - label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.idattribute")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fIdAttributeText= new Text(inner, SWT.BORDER); - - fIdAttributeText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fIdAttributeText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - //Id Source - createIdSourceGroup(inner); - - fElementText.setFocus(); - - return composite; - } - - /** - * Validate user input - */ - private void doValidation() { - StatusInfo status= new StatusInfo(); - String text= fElementText.getText(); - String mappingKey= Mapping.getKey(fSignatureText.getText(), text); - String errormsg= ""; //$NON-NLS-1$ - boolean isError= false; - if (text.length() == 0) { - errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.noname"); //$NON-NLS-1$ - isError= true; - } else if (XMLComparePreferencePage.containsInvalidCharacters(text)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.invalidname"); //$NON-NLS-2$ //$NON-NLS-1$ - isError= true; - } else if (!fEdit && fIdmapHM != null && fIdmapHM.containsKey(mappingKey)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.mappingExists"); //$NON-NLS-2$ //$NON-NLS-1$ - isError= true; - } - text= fSignatureText.getText(); - if (XMLComparePreferencePage.containsInvalidCharacters(text)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.invalidsignature"); //$NON-NLS-2$ //$NON-NLS-1$ - isError= true; - } - text= fIdAttributeText.getText(); - if (text.length() == 0) - isError= true; - else if (XMLComparePreferencePage.containsInvalidCharacters(text)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.invalididattribute"); //$NON-NLS-2$ //$NON-NLS-1$ - isError= true; - } - if (isError) status.setError(errormsg); - updateStatus(status); - } - - /** - * Notifies that the ok button of this dialog has been pressed. - */ - protected void okPressed() { - fMapping.setElement(fElementText.getText()); - fMapping.setSignature(fSignatureText.getText()); - String idtext= fIdAttributeText.getText(); - if (fIdTypeChildBodyButton.getSelection()) { - idtext= new Character(XMLStructureCreator.ID_TYPE_BODY) + idtext; - } - fMapping.setIdAttribute(idtext); - super.okPressed(); - } - - private void createIdSourceGroup(Composite composite) { - Label titleLabel= new Label(composite, SWT.NONE); - titleLabel.setText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.idtype")); //$NON-NLS-1$ - titleLabel.setToolTipText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.idtype.tooltip")); //$NON-NLS-1$ - - Composite buttonComposite= new Composite(composite, SWT.LEFT); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - buttonComposite.setLayout(layout); - composite.setData(new GridData()); - - //attribute button - fIdTypeAttributeButton= createRadioButton(buttonComposite, XMLCompareMessages.getString("XMLComparePreference.idtype.attribute")); //$NON-NLS-1$ - fIdTypeAttributeButton.setToolTipText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.idtype.attribute.tooltip")); //$NON-NLS-1$ - - //child body button - fIdTypeChildBodyButton= createRadioButton(buttonComposite, XMLCompareMessages.getString("XMLComparePreference.idtype.child_body")); //$NON-NLS-1$ - fIdTypeChildBodyButton.setToolTipText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.idtype.childbody.tooltip")); //$NON-NLS-1$ - - String idtext= fMapping.getIdAttribute(); - if (fEdit && idtext.charAt(0) == XMLStructureCreator.ID_TYPE_BODY) { - idtext= idtext.substring(1,idtext.length()); - fIdTypeChildBodyButton.setSelection(true); - } else - fIdTypeAttributeButton.setSelection(true); - fIdAttributeText.setText(idtext); - - } - - private Button createRadioButton(Composite parent, String label) { - Button button= new Button(parent, SWT.RADIO | SWT.LEFT); - button.setText(label); - GridData data= new GridData(); - button.setLayoutData(data); - return button; - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditOrderedDialog.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditOrderedDialog.java deleted file mode 100644 index 5fb35230a..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditOrderedDialog.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.ArrayList; - -import org.eclipse.compare.examples.xml.ui.StatusDialog; -import org.eclipse.compare.examples.xml.ui.StatusInfo; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * This class is used to add or edit a particular ID Mapping - */ -public class XMLCompareEditOrderedDialog extends StatusDialog { - - private Mapping fMapping; - private ArrayList fIdmapAL; - private boolean fEdit; - - private Text fElementText; - private Text fSignatureText; - - /** - * Constructs a new edit mapping dialog. - */ - public XMLCompareEditOrderedDialog(Shell parent, Mapping mapping, ArrayList idmapAL, boolean edit) { - super(parent); - - int shellStyle= getShellStyle(); - setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE); - - - fEdit= edit; - if (fEdit) - setTitle(XMLCompareMessages.getString("XMLCompareEditOrderedDialog.editTitle")); //$NON-NLS-1$ - else - setTitle(XMLCompareMessages.getString("XMLCompareEditOrderedDialog.newTitle")); //$NON-NLS-1$ - - fMapping= mapping; - fIdmapAL= idmapAL; - } - - /** - * Creates and returns the contents of the upper part - * of the dialog (above the button bar). - * - * Subclasses should override. - * - * @param the parent composite to contain the dialog area - * @return the dialog area control - */ - protected Control createDialogArea(Composite ancestor) { - Composite composite= (Composite) super.createDialogArea(ancestor); - - Composite inner= new Composite(composite, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - inner.setLayout(layout); - inner.setLayoutData(new GridData(GridData.FILL_BOTH)); - - //Element - Label label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.element")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fElementText= new Text(inner, SWT.BORDER); - fElementText.setText(fMapping.getElement()); - fElementText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fElementText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - //Signature - label= new Label(inner, SWT.NULL); - label.setText(XMLCompareMessages.getString("XMLCompareEditMappingDialog.signature")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - fSignatureText= new Text(inner, SWT.BORDER); - fSignatureText.setText(fMapping.getSignature()); - GridData data= new GridData(GridData.FILL_HORIZONTAL); - data.widthHint= convertWidthInCharsToPixels(50); - fSignatureText.setLayoutData(data); - fSignatureText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e){ - doValidation(); - } - }); - - fElementText.setFocus(); - - return composite; - } - - /** - * Validate user input - */ - private void doValidation() { - StatusInfo status= new StatusInfo(); - String text= fElementText.getText(); - String mappingKey= Mapping.getKey(fSignatureText.getText(), text); - String errormsg= ""; //$NON-NLS-1$ - boolean isError= false; - if (text.length() == 0) { - errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.noname"); //$NON-NLS-1$ - isError= true; - } else if (XMLComparePreferencePage.containsInvalidCharacters(text)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.invalidname"); //$NON-NLS-2$ //$NON-NLS-1$ - isError= true; - } else if (!fEdit && fIdmapAL.contains(mappingKey)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditOrderedDialog.error.orderedExists"); //$NON-NLS-1$ //$NON-NLS-2$ - isError= true; - } - text= fSignatureText.getText(); - if (XMLComparePreferencePage.containsInvalidCharacters(text)) { - if (errormsg == "") errormsg= XMLCompareMessages.getString("XMLCompareEditMappingDialog.error.invalidsignature"); //$NON-NLS-2$ //$NON-NLS-1$ - isError= true; - } - if (isError) status.setError(errormsg); - updateStatus(status); - } - - /** - * Notifies that the ok button of this dialog has been pressed. - */ - protected void okPressed() { - fMapping.setElement(fElementText.getText()); - fMapping.setSignature(fSignatureText.getText()); - super.okPressed(); - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareMessages.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareMessages.java deleted file mode 100644 index 79969d570..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareMessages.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class XMLCompareMessages { - - private static final String BUNDLE_NAME= "org.eclipse.compare.examples.xml.xmlcompare"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = - ResourceBundle.getBundle(BUNDLE_NAME); - - private XMLCompareMessages() { - } - - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLComparePreferencePage.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLComparePreferencePage.java deleted file mode 100644 index 612aff3c4..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLComparePreferencePage.java +++ /dev/null @@ -1,837 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.util.*; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.viewers.*; -import org.eclipse.jface.window.Window; - -import org.eclipse.ui.*; - -/** - * The XMLComparePreferencePage is the page used to set ID Mappings for XML Compare - */ -public class XMLComparePreferencePage extends PreferencePage implements IWorkbenchPreferencePage, Listener { - - private Table fIdMapsTable; - private Button fAddIdMapButton; - private Button fRenameIdMapButton; - private Button fRemoveIdMapButton; - private Button fEditIdMapButton; - - private Table fMappingsTable; - private Button fNewMappingsButton; - private Button fEditMappingsButton; - private Button fRemoveMappingsButton; - - private Table fOrderedTable; - private Button fNewOrderedButton; - private Button fEditOrderedButton; - private Button fRemoveOrderedButton; - - private HashMap fIdMapsInternal; - private HashMap fIdMaps;// HashMap ( idname -> HashMap (signature -> id) ) - private HashMap fIdExtensionToName; - - //fOrderedElements contains signature of xml element whose children must be compared in ordered fashion - private HashMap fOrderedElements;// HashMap ( idname -> ArrayList (signature) ) - private HashMap fOrderedElementsInternal; - - protected static char[] invalidCharacters; - protected static final char SIGN_SEPARATOR = XMLStructureCreator.SIGN_SEPARATOR; - - public static String IDTYPE_ATTRIBUTE= XMLCompareMessages.getString("XMLComparePreference.idtype.attribute"); //$NON-NLS-1$ - public static String IDTYPE_CHILDBODY= XMLCompareMessages.getString("XMLComparePreference.idtype.child_body"); //$NON-NLS-1$ - - - static { - invalidCharacters = new char[] {XMLPlugin.IDMAP_SEPARATOR,XMLPlugin.IDMAP_FIELDS_SEPARATOR,XMLStructureCreator.SIGN_ENCLOSING}; - } - - - public XMLComparePreferencePage() { - super(); - - fIdMaps = new HashMap(); - XMLPlugin plugin= XMLPlugin.getDefault(); - 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() ); - } - fIdMapsInternal = plugin.getIdMapsInternal(); - - 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)); - } - - fOrderedElements= new HashMap(); - HashMap PluginOrderedElements= plugin.getOrderedElements(); - keySet= PluginOrderedElements.keySet(); - for (Iterator iter= keySet.iterator(); iter.hasNext();) { - String key= (String) iter.next(); - fOrderedElements.put(key, ((ArrayList)PluginOrderedElements.get(key)).clone()); - } - - fOrderedElementsInternal= plugin.getOrderedElementsInternal(); - } - - /** - * @see PreferencePage#createContents(Composite) - */ - protected Control createContents(Composite ancestor) { - Composite parent= new Composite(ancestor, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.marginHeight= 0; - layout.marginWidth= 0; - parent.setLayout(layout); - - //layout the top table & its buttons - Label label = new Label(parent, SWT.LEFT); - label.setText(XMLCompareMessages.getString("XMLComparePreference.topTableLabel")); //$NON-NLS-1$ - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - label.setLayoutData(data); - - fIdMapsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); - fIdMapsTable.setHeaderVisible(true); - data = new GridData(GridData.FILL_BOTH); - data.heightHint = fIdMapsTable.getItemHeight()*4; - fIdMapsTable.setLayoutData(data); - fIdMapsTable.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - selectionChanged(); - } - }); - - String column2Text= XMLCompareMessages.getString("XMLComparePreference.topTableColumn2"); //$NON-NLS-1$ - String column3Text= XMLCompareMessages.getString("XMLComparePreference.topTableColumn3"); //$NON-NLS-1$ - ColumnLayoutData columnLayouts[]= { - new ColumnWeightData(1), - new ColumnPixelData(convertWidthInCharsToPixels(column2Text.length()+2), true), - new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length()+5), true)}; - TableLayout tablelayout = new TableLayout(); - fIdMapsTable.setLayout(tablelayout); - for (int i=0; i<3; i++) - tablelayout.addColumnData(columnLayouts[i]); - TableColumn column = new TableColumn(fIdMapsTable, SWT.NONE); - column.setText(XMLCompareMessages.getString("XMLComparePreference.topTableColumn1")); //$NON-NLS-1$ - column = new TableColumn(fIdMapsTable, SWT.NONE); - column.setText(column2Text); //$NON-NLS-1$ - column = new TableColumn(fIdMapsTable, SWT.NONE); - column.setText(column3Text); //$NON-NLS-1$ - - fillIdMapsTable(); - - Composite buttons= new Composite(parent, SWT.NULL); - buttons.setLayout(new GridLayout()); - data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - buttons.setLayoutData(data); - - fAddIdMapButton = new Button(buttons, SWT.PUSH); - fAddIdMapButton.setText(XMLCompareMessages.getString("XMLComparePreference.topAdd")); //$NON-NLS-1$ - fAddIdMapButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - addIdMap(fAddIdMapButton.getShell()); - } - }); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); - int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); - data.widthHint = Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); - fAddIdMapButton.setLayoutData(data); - - fRenameIdMapButton = new Button(buttons, SWT.PUSH); - fRenameIdMapButton.setText(XMLCompareMessages.getString("XMLComparePreference.topRename")); //$NON-NLS-1$ - fRenameIdMapButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - renameIdMap(fRenameIdMapButton.getShell()); - } - }); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); - widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); - data.widthHint = Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); - fRenameIdMapButton.setLayoutData(data); - - fRemoveIdMapButton = new Button(buttons, SWT.PUSH); - fRemoveIdMapButton.setText(XMLCompareMessages.getString("XMLComparePreference.topRemove")); //$NON-NLS-1$ - fRemoveIdMapButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - removeIdMap(fRemoveIdMapButton.getShell()); - } - }); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); - widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); - data.widthHint = Math.max(widthHint, fRemoveIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); - fRemoveIdMapButton.setLayoutData(data); - - createSpacer(buttons); - - fEditIdMapButton = new Button(buttons, SWT.PUSH); - fEditIdMapButton.setText(XMLCompareMessages.getString("XMLComparePreference.topEdit")); //$NON-NLS-1$ - fEditIdMapButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - editIdMap(fEditIdMapButton.getShell()); - } - }); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); - widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); - data.widthHint = Math.max(widthHint, fEditIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); - fEditIdMapButton.setLayoutData(data); - - //Spacer - label = new Label(parent, SWT.LEFT); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - label.setLayoutData(data); - - //layout the middle table & its buttons - label = new Label(parent, SWT.LEFT); - label.setText(XMLCompareMessages.getString("XMLComparePreference.middleTableLabel")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - label.setLayoutData(data); - - fMappingsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); - fMappingsTable.setHeaderVisible(true); - data = new GridData(GridData.FILL_BOTH); - data.heightHint = fMappingsTable.getItemHeight()*4; - data.widthHint= convertWidthInCharsToPixels(70); - fMappingsTable.setLayoutData(data); - - column3Text= XMLCompareMessages.getString("XMLComparePreference.middleTableColumn3"); //$NON-NLS-1$ - String column4Text= XMLCompareMessages.getString("XMLComparePreference.middleTableColumn4"); //$NON-NLS-1$ - columnLayouts= new ColumnLayoutData[] { - new ColumnWeightData(10), - new ColumnWeightData(18), - new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length()+1), true), - new ColumnPixelData(convertWidthInCharsToPixels(column4Text.length()+3), true)}; - tablelayout = new TableLayout(); - fMappingsTable.setLayout(tablelayout); - for (int i=0; i<4; i++) - tablelayout.addColumnData(columnLayouts[i]); - column = new TableColumn(fMappingsTable, SWT.NONE); - column.setText(XMLCompareMessages.getString("XMLComparePreference.middleTableColumn1")); //$NON-NLS-1$ - column = new TableColumn(fMappingsTable, SWT.NONE); - column.setText(XMLCompareMessages.getString("XMLComparePreference.middleTableColumn2")); //$NON-NLS-1$ - column = new TableColumn(fMappingsTable, SWT.NONE); - column.setText(column3Text); //$NON-NLS-1$ - column = new TableColumn(fMappingsTable, SWT.NONE); - column.setText(column4Text); //$NON-NLS-1$ - - buttons= new Composite(parent, SWT.NULL); - buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - layout= new GridLayout(); - layout.marginHeight= 0; - layout.marginWidth= 0; - buttons.setLayout(layout); - - fNewMappingsButton= new Button(buttons, SWT.PUSH); - fNewMappingsButton.setLayoutData(getButtonGridData(fNewMappingsButton)); - fNewMappingsButton.setText(XMLCompareMessages.getString("XMLComparePreference.middleNew")); //$NON-NLS-1$ - fNewMappingsButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - addMapping(fAddIdMapButton.getShell()); - } - }); - - fEditMappingsButton= new Button(buttons, SWT.PUSH); - fEditMappingsButton.setLayoutData(getButtonGridData(fEditMappingsButton)); - fEditMappingsButton.setText(XMLCompareMessages.getString("XMLComparePreference.middleEdit")); //$NON-NLS-1$ - fEditMappingsButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - editMapping(fEditMappingsButton.getShell()); - } - }); - - fRemoveMappingsButton= new Button(buttons, SWT.PUSH); - fRemoveMappingsButton.setLayoutData(getButtonGridData(fRemoveMappingsButton)); - fRemoveMappingsButton.setText(XMLCompareMessages.getString("XMLComparePreference.middleRemove")); //$NON-NLS-1$ - fRemoveMappingsButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - removeMapping(fRemoveMappingsButton.getShell()); - } - }); - - createSpacer(buttons); - - //layout the botton table & its buttons - label = new Label(parent, SWT.LEFT); - label.setText(XMLCompareMessages.getString("XMLComparePreference.bottomTableLabel")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - label.setLayoutData(data); - - fOrderedTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); - fOrderedTable.setHeaderVisible(true); - data = new GridData(GridData.FILL_BOTH); - data.heightHint = fOrderedTable.getItemHeight()*2; - data.widthHint= convertWidthInCharsToPixels(70); - fOrderedTable.setLayoutData(data); - - columnLayouts= new ColumnLayoutData[] { - new ColumnWeightData(1), - new ColumnWeightData(1)}; - tablelayout = new TableLayout(); - fOrderedTable.setLayout(tablelayout); - for (int i=0; i<2; i++) - tablelayout.addColumnData(columnLayouts[i]); - column = new TableColumn(fOrderedTable, SWT.NONE); - column.setText(XMLCompareMessages.getString("XMLComparePreference.bottomTableColumn1")); //$NON-NLS-1$ - column = new TableColumn(fOrderedTable, SWT.NONE); - column.setText(XMLCompareMessages.getString("XMLComparePreference.bottomTableColumn2")); //$NON-NLS-1$ - - buttons= new Composite(parent, SWT.NULL); - buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - layout= new GridLayout(); - layout.marginHeight= 0; - layout.marginWidth= 0; - buttons.setLayout(layout); - - fNewOrderedButton= new Button(buttons, SWT.PUSH); - fNewOrderedButton.setLayoutData(getButtonGridData(fNewOrderedButton)); - fNewOrderedButton.setText(XMLCompareMessages.getString("XMLComparePreference.bottomNew")); //$NON-NLS-1$ - fNewOrderedButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - addOrdered(fNewOrderedButton.getShell()); - } - }); - - fEditOrderedButton= new Button(buttons, SWT.PUSH); - fEditOrderedButton.setLayoutData(getButtonGridData(fEditOrderedButton)); - fEditOrderedButton.setText(XMLCompareMessages.getString("XMLComparePreference.bottomEdit")); //$NON-NLS-1$ - fEditOrderedButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - editOrdered(fEditOrderedButton.getShell()); - } - }); - - fRemoveOrderedButton= new Button(buttons, SWT.PUSH); - fRemoveOrderedButton.setLayoutData(getButtonGridData(fRemoveOrderedButton)); - fRemoveOrderedButton.setText(XMLCompareMessages.getString("XMLComparePreference.bottomRemove")); //$NON-NLS-1$ - fRemoveOrderedButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - removeOrdered(fRemoveOrderedButton.getShell()); - } - }); - - createSpacer(buttons); - - - - fIdMapsTable.setSelection(0); - fIdMapsTable.setFocus(); - selectionChanged(); - - return parent; - } - - protected void createSpacer(Composite parent) { - Label spacer= new Label(parent, SWT.NONE); - GridData data= new GridData(); - data.horizontalAlignment= GridData.FILL; - data.verticalAlignment= GridData.BEGINNING; - data.heightHint= 4; - spacer.setLayoutData(data); - } - - private static GridData getButtonGridData(Button button) { - GridData data= new GridData(GridData.FILL_HORIZONTAL); - data.widthHint= SWTUtil.getButtonWidthHint(button); - data.heightHint= SWTUtil.getButtonHeigthHint(button); - - return data; - } - - public void init(IWorkbench workbench) { - noDefaultAndApplyButton(); - } - - public void handleEvent(Event event) { - } - - private void addIdMap(Shell shell) { - IdMap idmap = new IdMap(false); - XMLCompareAddIdMapDialog dialog= new XMLCompareAddIdMapDialog(shell,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()); - newIdMapsTableItem(idmap,true); - } - } - } - - private void renameIdMap(Shell shell) { - TableItem[] itemsIdMaps = fIdMapsTable.getSelection(); - if (itemsIdMaps.length > 0) { - IdMap idmap = (IdMap) itemsIdMaps[0].getData(); - String old_name = idmap.getName(); - String old_extension= idmap.getExtension(); - HashMap idmapHS = (HashMap) fIdMaps.get(old_name); - XMLCompareAddIdMapDialog dialog= new XMLCompareAddIdMapDialog(shell,idmap,fIdMaps,fIdMapsInternal,fIdExtensionToName,true); - if (dialog.open() == Window.OK) { - fIdMaps.remove(old_name); - fIdExtensionToName.remove(old_extension); - fIdMaps.put(idmap.getName(),idmapHS); - if (!idmap.getExtension().equals("")) //$NON-NLS-1$ - fIdExtensionToName.put(idmap.getExtension(),idmap.getName()); - fIdMapsTable.remove(fIdMapsTable.indexOf(itemsIdMaps[0])); - newIdMapsTableItem(idmap,true); - } - } - } - - private void removeIdMap(Shell shell) { - TableItem[] itemsIdMap = fIdMapsTable.getSelection(); - if (itemsIdMap.length > 0) { -// fIdMaps.remove(itemsIdMap[0].getText()); - String IdMapName= ((IdMap)itemsIdMap[0].getData()).getName(); - fIdMaps.remove( IdMapName ); - fOrderedElements.remove( IdMapName ); - //All the corresponding ID Mappings must be removed as well - TableItem[] itemsMappings = fMappingsTable.getItems(); - for (int i=0; i<itemsMappings.length; i++) { - itemsMappings[i].dispose(); - } - //All the corresponding Ordered entries must be removed as well - TableItem[] itemsOrdered= fOrderedTable.getItems(); - for (int i= 0; i < itemsOrdered.length; i++) { - itemsOrdered[i].dispose(); - } - //Remove extension - if (!itemsIdMap[0].getText(2).equals("")) { //$NON-NLS-1$ - fIdExtensionToName.remove(itemsIdMap[0].getText(2)); - } - itemsIdMap[0].dispose(); //Table is single selection - } - } - - private void editIdMap(Shell shell) { - TableItem[] items = fIdMapsTable.getSelection(); - if (items.length > 0) { - IdMap idmap = (IdMap) items[0].getData(); - XMLCompareEditCopyIdMapDialog dialog= new XMLCompareEditCopyIdMapDialog(shell,idmap,fIdMaps,fIdMapsInternal); - if (dialog.open() == Window.OK) { - String new_idmapName = dialog.getResult(); - if (!fIdMaps.containsKey(new_idmapName)) { - //copy over id mappings - Vector newMappings = new Vector(); - IdMap newIdMap = new IdMap(new_idmapName, false, newMappings); - HashMap newIdmapHM = new HashMap(); - fIdMaps.put(newIdMap.getName(),newIdmapHM); - Vector Mappings = idmap.getMappings(); - for (Enumeration enum= Mappings.elements(); enum.hasMoreElements(); ) { - Mapping mapping = (Mapping) enum.nextElement(); - Mapping newMapping = new Mapping(mapping.getElement(), mapping.getSignature(), mapping.getIdAttribute()); - newMappings.add(newMapping); - newIdmapHM.put(newMapping.getKey(), newMapping.getIdAttribute()); - } - //copy over ordered entries - ArrayList orderedAL= idmap.getOrdered(); - if (orderedAL != null && orderedAL.size() > 0) { - ArrayList newOrderedAL= new ArrayList(); - newIdMap.setOrdered(newOrderedAL); - ArrayList idmapOrdered= new ArrayList(); - fOrderedElements.put(newIdMap.getName(),idmapOrdered); - for (Iterator iter= orderedAL.iterator(); iter.hasNext();) { - Mapping ordered= (Mapping) iter.next(); - Mapping newOrdered= new Mapping(ordered.getElement(), ordered.getSignature()); - newOrderedAL.add(newOrdered); - idmapOrdered.add(newOrdered.getKey()); - } - } - - newIdMapsTableItem(newIdMap,true); - selectionChanged(); - } - } - } - } - - private void addMapping(Shell shell) { - TableItem[] items = fIdMapsTable.getSelection(); - if (items.length > 0) { - IdMap idmap = (IdMap) items[0].getData(); - Mapping mapping = new Mapping(); - HashMap idmapHM = (HashMap) fIdMaps.get(idmap.getName()); - XMLCompareEditMappingDialog dialog= new XMLCompareEditMappingDialog(shell,mapping,idmapHM,false); - if (dialog.open() == Window.OK) { - String idmapHMKey = mapping.getKey(); - if (idmapHM == null) - idmapHM= new HashMap(); - if (!idmapHM.containsKey(idmapHMKey)) { - idmapHM.put(idmapHMKey, mapping.getIdAttribute()); - newMappingsTableItem(mapping, true); - Vector mappings = idmap.getMappings(); - mappings.add(mapping); - } - } - } - } - - private void editMapping(Shell shell) { - TableItem[] itemsIdMaps = fIdMapsTable.getSelection(); - TableItem[] itemsMappings = fMappingsTable.getSelection(); - if (itemsMappings.length > 0) { - IdMap idmap = (IdMap) itemsIdMaps[0].getData(); - HashMap idmapHM = (HashMap) fIdMaps.get(idmap.getName()); - Mapping mapping = (Mapping)itemsMappings[0].getData(); - String idmapHMKey = mapping.getKey(); - idmapHM.remove(idmapHMKey); - XMLCompareEditMappingDialog dialog= new XMLCompareEditMappingDialog(shell,mapping,null,true); - if (dialog.open() == Window.OK) { - idmapHMKey = mapping.getKey(); - idmapHM.put(idmapHMKey, mapping.getIdAttribute()); - fMappingsTable.remove(fMappingsTable.indexOf(itemsMappings[0])); - newMappingsTableItem(mapping, true); - } - } - } - - private void removeMapping(Shell shell) { - TableItem[] itemsIdMaps = fIdMapsTable.getSelection(); - TableItem[] itemsMappings = fMappingsTable.getSelection(); - - if (itemsMappings.length > 0 && itemsIdMaps.length > 0) { - Mapping mapping = (Mapping)itemsMappings[0].getData(); - IdMap idmap = (IdMap) itemsIdMaps[0].getData(); - HashMap idmapHS = (HashMap) fIdMaps.get( idmap.getName() ); - idmapHS.remove(mapping.getKey()); - Vector mappings= idmap.getMappings(); - mappings.remove(mapping); - itemsMappings[0].dispose(); //Table is single selection - } - } - - private void addOrdered(Shell shell) { - TableItem[] items = fIdMapsTable.getSelection(); - if (items.length > 0) { -// Set orderedSet= fOrderedElements.keySet(); -// for (Iterator iter= orderedSet.iterator(); iter.hasNext(); ) { -// String IdMapName= (String) iter.next(); -// ArrayList ordered= (ArrayList) fOrderedElements.get(IdMapName); -// for (Iterator iter2= ordered.iterator(); iter2.hasNext(); ) { -// System.out.println(IdMapName + ": " + iter2.next()); //$NON-NLS-1$ -// } -// } - IdMap idmap = (IdMap) items[0].getData(); - Mapping mapping = new Mapping(); - ArrayList idmapAL= (ArrayList) fOrderedElements.get(idmap.getName()); - if (idmapAL == null) - idmapAL= new ArrayList(); - XMLCompareEditOrderedDialog dialog= new XMLCompareEditOrderedDialog(shell,mapping,idmapAL,false); - if (dialog.open() == Window.OK) { - String idmapALKey = mapping.getKey(); - if (!idmapAL.contains(idmapALKey)) { - idmapAL.add(idmapALKey); - newOrderedTableItem(mapping, true); - ArrayList ordered= idmap.getOrdered(); - if (ordered == null) { - ordered= new ArrayList(); - ordered.add(mapping); - idmap.setOrdered(ordered); - } else { - ordered.add(mapping); - } - if (!fOrderedElements.containsKey(idmap.getName())) - fOrderedElements.put(idmap.getName(), idmapAL); - } - } - } - } - - private void editOrdered(Shell shell) { - TableItem[] itemsIdMaps = fIdMapsTable.getSelection(); - TableItem[] itemsOrdered = fOrderedTable.getSelection(); - if (itemsOrdered.length > 0) { - IdMap idmap = (IdMap) itemsIdMaps[0].getData(); - ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName()); - Mapping mapping = (Mapping)itemsOrdered[0].getData(); - String idmapALKey = mapping.getKey(); - idmapAL.remove(idmapALKey); - XMLCompareEditOrderedDialog dialog= new XMLCompareEditOrderedDialog(shell,mapping,null,true); - if (dialog.open() == Window.OK) { - idmapALKey = mapping.getKey(); - idmapAL.add(idmapALKey); - fOrderedTable.remove(fOrderedTable.indexOf(itemsOrdered[0])); - newOrderedTableItem(mapping, true); - } - } - - } - - private void removeOrdered(Shell shell) { - TableItem[] itemsIdMaps = fIdMapsTable.getSelection(); - TableItem[] itemsOrdered = fOrderedTable.getSelection(); - if (itemsOrdered.length > 0 && itemsIdMaps.length > 0) { - Mapping mapping = (Mapping)itemsOrdered[0].getData(); - IdMap idmap = (IdMap) itemsIdMaps[0].getData(); - ArrayList idmapAL = (ArrayList) fOrderedElements.get( idmap.getName() ); - idmapAL.remove(mapping.getKey()); - if (idmapAL.size() <= 0) - fOrderedElements.remove(idmap.getName()); - ArrayList ordered= idmap.getOrdered(); - ordered.remove(mapping); - if (ordered.size() <= 0) - idmap.setOrdered(null); - itemsOrdered[0].dispose(); //Table is single selection - } - } - - protected TableItem newIdMapsTableItem(IdMap idmap, boolean selected) { - //find index where to insert table entry - TableItem[] items = fIdMapsTable.getItems(); - int i; - for (i=0; i<items.length && idmap.getName().compareToIgnoreCase(items[i].getText(0)) > 0; i++); - TableItem item = new TableItem(fIdMapsTable, SWT.NULL, i); - String[] values = new String[] {idmap.getName(), (idmap.isInternal())?XMLCompareMessages.getString("XMLComparePreference.topTableColumn2internal"):XMLCompareMessages.getString("XMLComparePreference.topTableColumn2user"),idmap.getExtension()}; //$NON-NLS-2$ //$NON-NLS-1$ - item.setText(values); - item.setData(idmap); - if (selected) { - fIdMapsTable.setSelection(i); - fIdMapsTable.setFocus(); - selectionChanged(); - } - return item; - } - - protected TableItem newMappingsTableItem(Mapping mapping, boolean selected) { - TableItem[] items = fMappingsTable.getItems(); - int i; - for (i=0; i<items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0; i++); - - TableItem item = new TableItem(fMappingsTable, SWT.NULL, i); - String idtext = mapping.getIdAttribute(); - String idtype; - if (idtext.charAt(0)==XMLStructureCreator.ID_TYPE_BODY) { - idtext = idtext.substring(1,idtext.length()); - idtype = IDTYPE_CHILDBODY; - } else - idtype = IDTYPE_ATTRIBUTE; - - String[] values = new String[] {mapping.getElement(), mapping.getSignature(), idtext, idtype}; - item.setText(values); - item.setData(mapping); - if (selected) - fMappingsTable.setSelection(i); - - return item; - } - - protected TableItem newOrderedTableItem(Mapping mapping, boolean selected) { - TableItem[] items = fOrderedTable.getItems(); - int i; - for (i=0; i<items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0; i++); - - TableItem item = new TableItem(fOrderedTable, SWT.NULL, i); - - String[] values = new String[] {mapping.getElement(), mapping.getSignature()}; - item.setText(values); - item.setData(mapping); - if (selected) - fOrderedTable.setSelection(i); - - return item; - } - - - protected void fillIdMapsTable() { - //fill user idmaps from plugin.xml - fillIdMaps(true); - - //fill user idmaps from Preference Store - fillIdMaps(false); - - //add user idmaps that have ordered entries but no id mappings - //they do not appear in the preference store with name IDMAP_PREFERENCE_NAME - Set OrderedKeys= fOrderedElements.keySet(); - Set IdMapKeys= fIdMaps.keySet(); - for (Iterator iter_orderedElements= OrderedKeys.iterator(); iter_orderedElements.hasNext();) { - String IdMapName= (String) iter_orderedElements.next(); - if (!IdMapKeys.contains(IdMapName)) { - IdMap idmap= new IdMap(IdMapName, false); - ArrayList idmapOrdered= (ArrayList) fOrderedElements.get(IdMapName); - setOrdered(idmap, idmapOrdered); - newIdMapsTableItem(idmap, false); - } - } - } - - private void fillIdMaps(boolean internal) { - HashMap IdMaps= (internal)?fIdMapsInternal:fIdMaps; - HashMap OrderedElements= (internal)?fOrderedElementsInternal:fOrderedElements; - Set IdMapKeys = IdMaps.keySet(); - for (Iterator iter_internal = IdMapKeys.iterator(); iter_internal.hasNext(); ) { - String IdMapName = (String) iter_internal.next(); - Vector Mappings = new Vector(); - IdMap idmap = new IdMap(IdMapName, internal, Mappings); - //create mappings of internal idmaps - HashMap idmapHM = (HashMap) IdMaps.get(IdMapName); - Set idmapKeys = idmapHM.keySet(); - for (Iterator iter_idmap = idmapKeys.iterator(); iter_idmap.hasNext(); ) { - Mapping mapping = new Mapping(); - String signature = (String) iter_idmap.next(); - int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR,signature.length()-2); - if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1) - mapping.setSignature(""); //$NON-NLS-1$ - else - mapping.setSignature(signature.substring(XMLStructureCreator.ROOT_ID.length() + 1,end_of_signature)); - mapping.setElement(signature.substring(end_of_signature+1,signature.length()-1)); - mapping.setIdAttribute((String)idmapHM.get(signature)); - Mappings.add(mapping); - } - //create ordered mappings - ArrayList idmapOrdered= (ArrayList) OrderedElements.get(IdMapName); - if (idmapOrdered != null) { - setOrdered(idmap, idmapOrdered); - } - //set extension - if (fIdExtensionToName.containsValue(IdMapName)) { - Set keySet= fIdExtensionToName.keySet(); - String extension= new String(); - for (Iterator iter= keySet.iterator(); iter.hasNext(); ) { - extension= (String)iter.next(); - if ( ((String)fIdExtensionToName.get(extension)).equals(IdMapName) ) - break; - } - idmap.setExtension(extension); - } - newIdMapsTableItem(idmap, false); - } - } - - protected static void setOrdered(IdMap idmap, ArrayList idmapOrdered) { - ArrayList Ordered= new ArrayList(); - for (Iterator iter_ordered= idmapOrdered.iterator(); iter_ordered.hasNext();) { - Mapping mapping= new Mapping(); - String signature= (String) iter_ordered.next(); - int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR,signature.length()-2); - if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1) - mapping.setSignature(""); //$NON-NLS-1$ - else - mapping.setSignature(signature.substring(XMLStructureCreator.ROOT_ID.length() + 1,end_of_signature)); - mapping.setElement(signature.substring(end_of_signature+1,signature.length()-1)); - Ordered.add(mapping); - } - idmap.setOrdered(Ordered); - } - - /** - * @see IWorkbenchPreferencePage#performDefaults - */ - public boolean performOk() { - XMLPlugin plugin= XMLPlugin.getDefault(); - if (!plugin.getIdMaps().equals(fIdMaps) - || !plugin.getIdExtensionToName().equals(fIdExtensionToName) - || !plugin.getOrderedElements().equals(fOrderedElements) ) - plugin.setIdMaps(fIdMaps,fIdExtensionToName,fOrderedElements,true); - //XMLPlugin.getDefault().setIdMaps(fIdMaps,fIdExtensionToName,null); - return super.performOk(); - } - - public boolean performCancel() { - fIdMaps = (HashMap) XMLPlugin.getDefault().getIdMaps().clone(); - return super.performCancel(); - } - - protected void selectionChanged() { - TableItem[] items = fIdMapsTable.getSelection(); - if (items.length > 0) { - //Refresh Mappings Table - fMappingsTable.removeAll(); - Vector Mappings = ((IdMap)items[0].getData()).getMappings(); - for (Enumeration enum = Mappings.elements(); enum.hasMoreElements(); ) { - newMappingsTableItem((Mapping)enum.nextElement(), false); - } - //Refresh Ordered Table - fOrderedTable.removeAll(); - ArrayList Ordered= ((IdMap)items[0].getData()).getOrdered(); - if (Ordered != null) { - for (Iterator iter_ordered= Ordered.iterator(); iter_ordered.hasNext();) { - newOrderedTableItem((Mapping)iter_ordered.next(), false); - } - } - } - updateEnabledState(); - } - - /** - * Updates the state (enabled, not enabled) of the buttons - */ - private void updateEnabledState() { - TableItem[] itemsIdMaps = fIdMapsTable.getSelection(); - if (itemsIdMaps.length > 0) { - IdMap idmap = (IdMap) itemsIdMaps[0].getData(); - if (idmap.isInternal()) { - fRenameIdMapButton.setEnabled(false); - fRemoveIdMapButton.setEnabled(false); - fEditIdMapButton.setEnabled(true); - - fNewMappingsButton.setEnabled(false); - fEditMappingsButton.setEnabled(false); - fRemoveMappingsButton.setEnabled(false); - - fNewOrderedButton.setEnabled(false); - fEditOrderedButton.setEnabled(false); - fRemoveOrderedButton.setEnabled(false); - } else { - fRenameIdMapButton.setEnabled(true); - fRemoveIdMapButton.setEnabled(true); - fEditIdMapButton.setEnabled(false); - - fNewMappingsButton.setEnabled(true); - fEditMappingsButton.setEnabled(true); - fRemoveMappingsButton.setEnabled(true); - - fNewOrderedButton.setEnabled(true); - fEditOrderedButton.setEnabled(true); - fRemoveOrderedButton.setEnabled(true); - } - } - } - - static protected boolean containsInvalidCharacters(String text) { - for (int i=0; i<invalidCharacters.length; i++) { - if (text.indexOf(invalidCharacters[i]) > -1) - return true; - } - return false; - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLNode.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLNode.java deleted file mode 100644 index 91ea36cf3..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLNode.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import org.eclipse.compare.CompareUI; -import org.eclipse.compare.ITypedElement; -import org.eclipse.compare.structuremergeviewer.DocumentRangeNode; -import org.eclipse.jface.text.IDocument; -import org.eclipse.swt.graphics.Image; - -/** - * Objects that make up the parse tree. - */ -public class XMLNode extends DocumentRangeNode implements ITypedElement { - - private String fValue; - private String fName; - private String fSignature; - private String fOrigId; - private XMLNode parent; - private String fXMLType; - private boolean fUsesIDMAP; - private boolean fOrderedChild; - - public int bodies; // counts the number of bodies - - public XMLNode(String XMLType, String id, String value, String signature, IDocument doc, int start, int length) { - super(0, id, doc, start, length); - fXMLType= XMLType; - fValue= value; - fSignature= signature; - fOrigId= id; - if (XMLStructureCreator.DEBUG_MODE) - System.out.println("Created XMLNode with XMLType: " + XMLType + ", id: " + id + ", value: " + value + ", signature: " + fSignature); //$NON-NLS-1$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ - bodies= 0; - fUsesIDMAP= false; - fOrderedChild= false; - } - - void setValue(String value) { - fValue= value; - } - - String getValue() { - return fValue; - } - - /** - * @see ITypedElement#getName - */ - public String getName() { - if (fName != null) - return fName; - return this.getId(); - } - - public void setName(String name) { - fName= name; - } - - /** - * Every xml node is of type "txt" so that the builtin TextMergeViewer is used automatically. - * @see ITypedElement#getType - */ - public String getType() { - return "txt"; //$NON-NLS-1$ - } - - public void setIsOrderedChild(boolean isOrderedChild) { - fOrderedChild= isOrderedChild; - } - /** - * @see ITypedElement#getImage - */ - public Image getImage() { - if (fOrderedChild) - return CompareUI.getImage( - XMLPlugin.IMAGE_TYPE_PREFIX - + XMLStructureCreator.TYPE_ELEMENT - + XMLPlugin.IMAGE_TYPE_ORDERED_SUFFIX); - else - return CompareUI.getImage( - XMLPlugin.IMAGE_TYPE_PREFIX + getXMLType()); - } - - public void setParent(XMLNode parent0) { - this.parent= parent0; - } - - public XMLNode getParent() { - return this.parent; - } - - String getXMLType() { - return fXMLType; - } - - String getSignature() { - return fSignature; - } - - void setOrigId(String id) { - fOrigId= id; - } - - public String getOrigId() { - return fOrigId; - } - - public void setUsesIDMAP(boolean b) { - fUsesIDMAP= b; - } - - public boolean usesIDMAP() { - return fUsesIDMAP; - } - - //for tests - public boolean testEquals(Object obj) { - if (obj instanceof XMLNode) { - XMLNode n= (XMLNode) obj; - return fValue.equals(n.getValue()) - && fSignature.equals(n.getSignature()) - && fXMLType.equals(n.getXMLType()) - && fUsesIDMAP == n.usesIDMAP(); - } - return false; - } - - /** - * Returns true if the subtree rooted at this node is equals to the subtree rooted at <code>obj</code> - */ - public boolean subtreeEquals(Object obj) { - if (!testEquals(obj)) - return false; - if (obj instanceof XMLNode) { - XMLNode n= (XMLNode) obj; - if (getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE) - && n.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) - return true; - Object[] children= getChildren(); - Object[] n_children= n.getChildren(); - //if both nodes have no children, return true; - if ((children == null || children.length <= 0) - && (n_children == null || n_children.length <= 0)) - return true; - //now at least one of the two nodes has children; - /* so if one of the two nodes has no children, or they don't have the same number of children, - * return false; - */ - if ((children == null || children.length <= 0) - || (n_children == null || n_children.length <= 0) - || (children.length != n_children.length)) - return false; - //now both have children and the same number of children - for (int i= 0; i < children.length; i++) { - /* if the subtree rooted at children[i] is not equal to the subtree rooted at n_children[i], - * return false - */ - if (!((XMLNode) children[i]).subtreeEquals(n_children[i])) - return false; - } - } - return true; - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLPlugin.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLPlugin.java deleted file mode 100644 index 90de2894d..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLPlugin.java +++ /dev/null @@ -1,395 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.*; - -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.util.ListenerList; - -import org.eclipse.compare.CompareUI; -import org.eclipse.core.runtime.*; - -/** - * This class is the plug-in runtime class for the - * <code>"org.eclipse.compare.xml"</code> plug-in. - * </p> - */ -public final class XMLPlugin extends AbstractUIPlugin { - - private ListenerList fViewers; - - public static final String PLUGIN_ID= "org.eclipse.compare.examples.xml"; //$NON-NLS-1$ - - private static final String ID_MAPPING_EXTENSION_POINT= "idMapping"; //$NON-NLS-1$ - private static final String MAPPING_ELEMENT_NAME= "mapping"; //$NON-NLS-1$ - private static final String IDMAP_NAME_ATTRIBUTE= "name"; //$NON-NLS-1$ - private static final String EXTENSION_NAME_ATTRIBUTE= "extension"; //$NON-NLS-1$ - private static final String MAPPING_SIGNATURE_ATTRIBUTE= "signature"; //$NON-NLS-1$ - private static final String MAPPING_ID_ATTRIBUTE= "id"; //$NON-NLS-1$ - private static final String MAPPING_ID_SOURCE= "id-source"; //$NON-NLS-1$ - private static final String MAPPING_ID_SOURCE_BODY= "body"; //$NON-NLS-1$ - private static final String ORDERED_ELEMENT_NAME= "ordered"; //$NON-NLS-1$ - private static final String ORDERED_SIGNATURE_ATTRIBUTE= "signature"; //$NON-NLS-1$ - - public static final String DEFAULT_PREFIX = "XML"; //$NON-NLS-1$ - public static final String IMAGE_TYPE_PREFIX = "xml_"; //$NON-NLS-1$ - public static final String IMAGE_TYPE_ORDERED_SUFFIX = "_ordered"; //$NON-NLS-1$ - public static final String IDMAP_PREFERENCE_NAME = "idmap"; //$NON-NLS-1$ - public static final String IDMAP_PREFIX = "idmap"; //$NON-NLS-1$ - public static final char IDMAP_SEPARATOR = '*'; - public static final char IDMAP_FIELDS_SEPARATOR = '!'; - - public static final String ORDERED_PREFERENCE_NAME = "ordered"; //$NON-NLS-1$ - public static final char ORDERED_FIELDS_SEPARATOR = IDMAP_FIELDS_SEPARATOR; - - private static XMLPlugin fgXMLPlugin; - private IPreferenceStore fPrefStore; - - private HashMap fIdMapsInternal; - private HashMap fIdMaps; - private HashMap fIdExtensionToName; - private HashMap fOrderedElementsInternal; - private HashMap fOrderedElements; - - /** - * Creates the <code>XMLPlugin</code> object and registers all - * structure creators, content merge viewers, and structure merge viewers - * contributed to this plug-in's extension points. - * <p> - * Note that instances of plug-in runtime classes are automatically created - * by the platform in the course of plug-in activation. - * </p> - * - * @param descriptor the plug-in descriptor - */ - public XMLPlugin(IPluginDescriptor descriptor) { - super(descriptor); - fgXMLPlugin= this; - fViewers = new ListenerList(); - - CompareUI.removeAllStructureViewerAliases(DEFAULT_PREFIX); - initPrefStore(); - CompareUI.registerImageDescriptor(IMAGE_TYPE_PREFIX + XMLStructureCreator.TYPE_ELEMENT, getImageDescriptor("obj16/element_obj.gif")); //$NON-NLS-1$ - CompareUI.registerImageDescriptor(IMAGE_TYPE_PREFIX + XMLStructureCreator.TYPE_ATTRIBUTE, getImageDescriptor("obj16/attribute_obj.gif")); //$NON-NLS-1$ - CompareUI.registerImageDescriptor(IMAGE_TYPE_PREFIX + XMLStructureCreator.TYPE_TEXT, getImageDescriptor("obj16/text_obj.gif")); //$NON-NLS-1$ - CompareUI.registerImageDescriptor(IMAGE_TYPE_PREFIX + XMLStructureCreator.TYPE_ELEMENT + IMAGE_TYPE_ORDERED_SUFFIX, getImageDescriptor("obj16/element_ordered_obj.gif")); //$NON-NLS-1$ - registerExtensions(); - } - - protected ImageDescriptor getImageDescriptor(String relativePath) { - - URL installURL= getDescriptor().getInstallURL(); - if (installURL != null) { - try { - URL url= new URL(installURL, "icons/full/" + relativePath); //$NON-NLS-1$ - return ImageDescriptor.createFromURL(url); - } catch (MalformedURLException e) { - Assert.isTrue(false); - } - } - return null; - } - - /** - * Returns the singleton instance of this plug-in runtime class. - * - * @return the XMLPlugin instance - */ - public static XMLPlugin getDefault() { - return fgXMLPlugin; - } - - /** - * Reads the Preference Store associated with XMLPlugin and initializes ID Mappings. - */ - public void initPrefStore() { - fIdMaps = new HashMap(); - fIdExtensionToName= new HashMap(); - fPrefStore = getPreferenceStore(); - String IdMapPrefValue = fPrefStore.getString(IDMAP_PREFERENCE_NAME); - int start = 0; - int end = IdMapPrefValue.indexOf(IDMAP_SEPARATOR); - while (end >= 0) { - String CurrentIdMap = IdMapPrefValue.substring(start,end); - int end_of_IdMapName = CurrentIdMap.indexOf(IDMAP_FIELDS_SEPARATOR); - String IdMapName = CurrentIdMap.substring(0,end_of_IdMapName); - int end_of_signature = CurrentIdMap.indexOf(IDMAP_FIELDS_SEPARATOR,end_of_IdMapName+1); - String IdMapSignature = CurrentIdMap.substring(end_of_IdMapName+1,end_of_signature); - int end_of_attribute= CurrentIdMap.indexOf(IDMAP_FIELDS_SEPARATOR,end_of_signature+1); - String IdMapAttribute; - if (end_of_attribute < 0) {//for backward compatibility - IdMapAttribute = CurrentIdMap.substring(end_of_signature+1,CurrentIdMap.length()); - } else {//normal case - IdMapAttribute = CurrentIdMap.substring(end_of_signature+1,end_of_attribute); - String IdMapExtension= CurrentIdMap.substring(end_of_attribute+1,CurrentIdMap.length()); - //if extension already associated, do not associate with this idmap - if (!IdMapExtension.equals("") && !fIdExtensionToName.containsKey(IdMapExtension)) { //$NON-NLS-1$ - fIdExtensionToName.put(IdMapExtension,IdMapName); - CompareUI.addStructureViewerAlias(DEFAULT_PREFIX, IdMapExtension); - } - } - - if (fIdMaps.containsKey(IdMapName)) { - HashMap Mappings = (HashMap) fIdMaps.get(IdMapName); - Mappings.put(IdMapSignature,IdMapAttribute); - } else { - HashMap Mappings = new HashMap(); - Mappings.put(IdMapSignature,IdMapAttribute); - fIdMaps.put(IdMapName,Mappings); - } - start = end+1; - end = IdMapPrefValue.indexOf(IDMAP_SEPARATOR,end+1); - } - - fOrderedElements= new HashMap(); - String OrderedPrefValue= fPrefStore.getString(ORDERED_PREFERENCE_NAME); - StringTokenizer orderedTokens= new StringTokenizer(OrderedPrefValue, (new Character(ORDERED_FIELDS_SEPARATOR)).toString()); - while (orderedTokens.hasMoreTokens()) { - String IdMapName= orderedTokens.nextToken(); - String signature= orderedTokens.nextToken(); - if (fOrderedElements.containsKey(IdMapName)) { - ArrayList idmapAL= (ArrayList) fOrderedElements.get(IdMapName); - idmapAL.add(signature); - } else { - ArrayList idmapAL= new ArrayList(); - idmapAL.add(signature); - fOrderedElements.put(IdMapName, idmapAL); - } - } - - } - - /** - * Updates the user Id Mappings, the IdExtensionToName mappings and refreshes the preference store. - * @param IdMap the new Id Mappings - * @param IdExtensionToName the new IdExtensionToName mappings - * @param refresh whether all the open StructureViewers should be refreshed with the new IdMapping settings - */ - public void setIdMaps(HashMap IdMap, HashMap IdExtensionToName, HashMap OrderedElements, boolean refresh) { - fIdMaps = IdMap; - if (IdExtensionToName != null && !IdExtensionToName.equals(fIdExtensionToName)) { - CompareUI.removeAllStructureViewerAliases(DEFAULT_PREFIX); - fIdExtensionToName= IdExtensionToName; - Set newkeySet= fIdExtensionToName.keySet(); - for (Iterator iter= newkeySet.iterator(); iter.hasNext(); ) { - String extension= (String)iter.next(); - CompareUI.addStructureViewerAlias(DEFAULT_PREFIX, extension); - } - } - StringBuffer IdMapPrefValue = new StringBuffer(); - Set idmapKeys = fIdMaps.keySet(); - for (Iterator iter_idmap = idmapKeys.iterator(); iter_idmap.hasNext(); ) { - String IdMapName = (String) iter_idmap.next(); - HashMap idmapHM = (HashMap) fIdMaps.get(IdMapName); - Set mappingKeys = idmapHM.keySet(); - String extension= ""; //$NON-NLS-1$ - if (fIdExtensionToName.containsValue(IdMapName)) { - Set keySet= fIdExtensionToName.keySet(); - for (Iterator iter= keySet.iterator(); iter.hasNext(); ) { - extension= (String)iter.next(); - if ( ((String)fIdExtensionToName.get(extension)).equals(IdMapName) ) - break; - } - } - for (Iterator iter_mapping = mappingKeys.iterator(); iter_mapping.hasNext(); ) { - String signature = (String) iter_mapping.next(); - IdMapPrefValue.append(IdMapName+IDMAP_FIELDS_SEPARATOR+signature+IDMAP_FIELDS_SEPARATOR+idmapHM.get(signature)+IDMAP_FIELDS_SEPARATOR+extension+IDMAP_SEPARATOR); - } - } - fPrefStore.setValue(IDMAP_PREFERENCE_NAME,IdMapPrefValue.toString()); - //fPrefStore.setValue(IDMAP_PREFERENCE_NAME,""); - - //stores OrderedElements - if (OrderedElements != null) { - fOrderedElements= OrderedElements; - StringBuffer OrderedPrefValue= new StringBuffer(); - Set orderedKeys= fOrderedElements.keySet(); - for (Iterator iter_ordered= orderedKeys.iterator(); iter_ordered.hasNext();) { - String IdMapName= (String) iter_ordered.next(); - ArrayList idmapAL= (ArrayList) fOrderedElements.get(IdMapName); - for (Iterator iter_idmapAL= idmapAL.iterator(); iter_idmapAL.hasNext();) { - String signature= (String) iter_idmapAL.next(); - OrderedPrefValue.append(IdMapName+ORDERED_FIELDS_SEPARATOR+signature+ORDERED_FIELDS_SEPARATOR); - } - } - fPrefStore.setValue(ORDERED_PREFERENCE_NAME,OrderedPrefValue.toString()); - //fPrefStore.setValue(ORDERED_PREFERENCE_NAME,""); - } - - if (refresh) { - Object[] viewers = fViewers.getListeners(); - for (int i = 0; i < viewers.length; ++i) { - XMLStructureViewer viewer = (XMLStructureViewer) viewers[i]; - viewer.updateIdMaps(); - viewer.contentChanged(); - } - } - } - - public HashMap getIdMaps() { - return fIdMaps; - } - - public HashMap getIdMapsInternal() { - return fIdMapsInternal; - } - - public HashMap getIdExtensionToName() { - return fIdExtensionToName; - } - - public HashMap getOrderedElements() { - return fOrderedElements; - } - - public HashMap getOrderedElementsInternal() { - return fOrderedElementsInternal; - } - - /** - * Registers all internal Id Mapping schemes - * that are found in plugin.xml files. - */ - private void registerExtensions() { - IPluginRegistry registry= Platform.getPluginRegistry(); - - // collect all Id Mappings - IConfigurationElement[] idmaps= registry.getConfigurationElementsFor(PLUGIN_ID, ID_MAPPING_EXTENSION_POINT); - fIdMapsInternal = new HashMap(); - fOrderedElementsInternal= new HashMap(); - for (int i_idmap= 0; i_idmap < idmaps.length; i_idmap++) { - final IConfigurationElement idmap= idmaps[i_idmap]; - //handle IDMAP_NAME_ATTRIBUTE - String idmap_name= idmap.getAttribute(IDMAP_NAME_ATTRIBUTE); - //ignores idmap if its name equals the reserved name for unordered matching or the the name for ordered matching - if ( !idmap_name.equals(XMLStructureCreator.USE_UNORDERED) && !idmap_name.equals(XMLStructureCreator.USE_ORDERED) ) { - //handle mappings - HashMap idmapHM = new HashMap(); - fIdMapsInternal.put(idmap_name, idmapHM); - IConfigurationElement[] mappings = idmap.getChildren(MAPPING_ELEMENT_NAME); - for (int i_mapping= 0; i_mapping < mappings.length; i_mapping++) { - IConfigurationElement mapping = mappings[i_mapping]; - //add SIGN_SEPARATOR at the end because not contained in signatures of plugin.xml - //also add prefix at beginning - String signature= mapping.getAttribute(MAPPING_SIGNATURE_ATTRIBUTE); - String attribute= mapping.getAttribute(MAPPING_ID_ATTRIBUTE); - String idsource= mapping.getAttribute(MAPPING_ID_SOURCE); - String bodyid= ""; //$NON-NLS-1$ - if (signature != null && !signature.equals("") //$NON-NLS-1$ - && attribute != null && !attribute.equals("")) { //$NON-NLS-1$ - if (idsource != null && idsource.equals(MAPPING_ID_SOURCE_BODY)) - bodyid= (new Character(XMLStructureCreator.ID_TYPE_BODY)).toString(); - idmapHM.put(XMLStructureCreator.ROOT_ID + XMLStructureCreator.SIGN_SEPARATOR - + signature + XMLStructureCreator.SIGN_SEPARATOR, bodyid + attribute); - } - } - //handles ordered entries - IConfigurationElement[] orderedEntries= idmap.getChildren(ORDERED_ELEMENT_NAME); - if (orderedEntries.length > 0) { - ArrayList orderedAL= new ArrayList(); - for (int i_ordered= 0; i_ordered < orderedEntries.length; i_ordered++) { - IConfigurationElement ordered= orderedEntries[i_ordered]; - //add SIGN_SEPARATOR at the end because not contained in signatures of plugin.xml - //also add prefix at beginning - String signature= ordered.getAttribute(ORDERED_SIGNATURE_ATTRIBUTE); - if (signature != null && !signature.equals("")) //$NON-NLS-1$ - orderedAL.add(XMLStructureCreator.ROOT_ID + XMLStructureCreator.SIGN_SEPARATOR + signature + XMLStructureCreator.SIGN_SEPARATOR); - } - if (orderedAL.size() > 0) - fOrderedElementsInternal.put(idmap_name, orderedAL); - } - //handle EXTENSION_NAME_ATTRIBUTE - String ext_name= idmap.getAttribute(EXTENSION_NAME_ATTRIBUTE); - if (ext_name != null && !fIdExtensionToName.containsKey(ext_name)) { - ext_name= ext_name.toLowerCase(); - fIdExtensionToName.put(ext_name,idmap_name); - CompareUI.addStructureViewerAlias(DEFAULT_PREFIX, ext_name); - } - } - } - } - - public ListenerList getViewers() { - return fViewers; - } - - public static Shell getActiveWorkbenchShell() { - IWorkbenchWindow window= getActiveWorkbenchWindow(); - if (window != null) - return window.getShell(); - return null; - } - - public static IWorkbenchWindow getActiveWorkbenchWindow() { - IWorkbenchWindow window= fgXMLPlugin.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - final WindowRef windowRef= new WindowRef(); - Display.getDefault().syncExec(new Runnable() { - public void run() { - setActiveWorkbenchWindow(windowRef); - } - }); - return windowRef.window; - } - else - return window; - } - - private static class WindowRef { - public IWorkbenchWindow window; - } - - private static void setActiveWorkbenchWindow(WindowRef windowRef) { - windowRef.window= null; - Display display= Display.getCurrent(); - if (display == null) - return; - Control shell= display.getActiveShell(); - while (shell != null) { - Object data= shell.getData(); - if (data instanceof IWorkbenchWindow) { - windowRef.window= (IWorkbenchWindow)data; - return; - } - shell= shell.getParent(); - } - Shell shells[]= display.getShells(); - for (int i= 0; i < shells.length; i++) { - Object data= shells[i].getData(); - if (data instanceof IWorkbenchWindow) { - windowRef.window= (IWorkbenchWindow)data; - return; - } - } - } - - public static void log(Throwable e) { - log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, "Internal Error", e)); //$NON-NLS-1$ - } - - public static void log(IStatus status) { - getDefault().getLog().log(status); - } - - public static String getPluginId() { - return getDefault().getDescriptor().getUniqueIdentifier(); - } - -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java deleted file mode 100644 index 57e548d64..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java +++ /dev/null @@ -1,741 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.compare.IEditableContent; -import org.eclipse.compare.IStreamContentAccessor; -import org.eclipse.compare.structuremergeviewer.Differencer; -import org.eclipse.compare.structuremergeviewer.IDiffContainer; -import org.eclipse.compare.structuremergeviewer.IStructureComparator; -import org.eclipse.compare.structuremergeviewer.IStructureCreator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Position; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; -import org.xml.sax.helpers.LocatorImpl; - -/** - * This structure analyzer builds a parse tree of an XML document found in - * a <code>IByteContentAccessor</code> input by calling getStructure(Object) - */ -public class XMLStructureCreator implements IStructureCreator { - - protected static final boolean DEBUG_MODE = false; - - private XMLNode fcurrentParent; - private String fsignature; - private Document fdoc; - private boolean ignoreBodies = false; - //private String fName; - - public static final String DEFAULT_NAME = XMLCompareMessages.getString("XMLStructureCreator.pluginname"); //$NON-NLS-1$ - - private HashMap fIdMapsInternal; - private HashMap fIdMaps; - private HashMap fIdExtensionToName; - private HashMap fOrderedElementsInternal; - private HashMap fOrderedElements; - private HashMap idMap; - private ArrayList fOrdered; - - public static final String USE_UNORDERED = XMLCompareMessages.getString("XMLStructureCreator.unordered"); //$NON-NLS-1$ - public static final String USE_ORDERED = XMLCompareMessages.getString("XMLStructureCreator.ordered"); //$NON-NLS-1$ - public static final String DEFAULT_IDMAP= USE_ORDERED; - private String fIdMapToUse; - private boolean fUseIdMap; - - public static final String TYPE_ELEMENT = "element"; //$NON-NLS-1$ - public static final String TYPE_TEXT = "text"; //$NON-NLS-1$ - public static final String TYPE_ATTRIBUTE = "attribute"; //$NON-NLS-1$ - - //for signatures - public static final String ROOT_ID = "root"; //$NON-NLS-1$ - public static final char SIGN_SEPARATOR = '>';//'.' - public static final char SIGN_ENCLOSING = '$'; - public static final String SIGN_ELEMENT = SIGN_ENCLOSING + TYPE_ELEMENT + SIGN_ENCLOSING; - public static final String SIGN_TEXT = SIGN_ENCLOSING + TYPE_TEXT + SIGN_ENCLOSING; - public static final String SIGN_ATTRIBUTE = SIGN_ENCLOSING + TYPE_ATTRIBUTE + SIGN_ENCLOSING; - - public static final String IDMAP_UNORDERED = XMLCompareMessages.getString("XMLStructureCreator.idmap_unordered"); //$NON-NLS-1$ - - public static final char ID_SEPARATOR = '<'; - public static final char ID_TYPE_BODY = '<'; - - //private static final String parserName = "org.apache.xerces.parsers.SAXParser"; //$NON-NLS-1$ - private static final String parserName = "org.apache.crimson.parser.XMLReaderImpl"; //$NON-NLS-1$ - - private static boolean setValidation = false; //defaults - private static boolean setNameSpaces = true; - private static boolean setSchemaSupport = true; - private static boolean setSchemaFullSupport = false; - - private String fFileExt; - private boolean fFirstCall = true; - - private boolean fRemoveWhiteSpace; - - protected class XMLHandler extends DefaultHandler { - - protected Locator prevlocator; //previous locator - protected Locator locator; //current locator - - public void setDocumentLocator (Locator locator0) { - this.locator = locator0; - } - - // - // DocumentHandler methods - // - /** Processing instruction. */ - public void processingInstruction(String target, String data) { - -// System.out.println("target: " + target); -// System.out.println("data: " + data); -// System.out.print("<?"); -// System.out.print(target); -// if (data != null && data.length() > 0) { -// System.out.print(' '); -// System.out.print(data); -// } -// System.out.print("?>"); -// System.out.flush(); - prevlocator = new LocatorImpl(locator); - } // processingInstruction(String,String) - - /** Start document. */ - public void startDocument() { - - prevlocator = new LocatorImpl(locator); - - } // startDocument() - - /** Start element. */ - public void startElement(String uri, String local, String raw, - Attributes attrs) { - XMLNode currentElement; - - /* add root node for this element */ - - if (XMLStructureCreator.DEBUG_MODE) { - if (locator != null && prevlocator != null) { - System.out.println("prevlocator: line " + prevlocator.getLineNumber() + " column " + prevlocator.getColumnNumber() + " id " + prevlocator.getPublicId()); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - System.out.println("locator: line " + locator.getLineNumber() + " column " + locator.getColumnNumber() + " id " + locator.getPublicId()); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - } - } - - try { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Node where children field accessed: " + fcurrentParent.getId()); //$NON-NLS-1$ - XMLChildren currentParent = (XMLChildren) fcurrentParent; - currentParent.children++; - String elementId; - String elementName; - IRegion r= fdoc.getLineInformation(prevlocator.getLineNumber()-1); - - String parentSig= fsignature; - fsignature = fsignature + raw + SIGN_SEPARATOR; - - if ( isUseIdMap() && idMap.containsKey(fsignature) ) { - String attrName = (String)idMap.get(fsignature); - elementId = raw + new Character(ID_SEPARATOR) + attrs.getValue(attrName); - elementName = raw + " [" + attrName + "=" + attrs.getValue(attrName) + "]"; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - } else { - if ( !currentParent.childElements.containsKey(raw) ) { - currentParent.childElements.put(raw,new Integer(1)); - } else { - currentParent.childElements.put(raw,new Integer(((Integer)currentParent.childElements.get(raw)).intValue()+1)); - } - elementId = raw+new Character(ID_SEPARATOR)+"["+currentParent.childElements.get(raw)+"]"; //$NON-NLS-2$ //$NON-NLS-1$ - elementName = MessageFormat.format("{0} [{1}]",new String[] {raw,currentParent.childElements.get(raw).toString()}); //$NON-NLS-2$ //$NON-NLS-1$ - } - currentElement = new XMLChildren(TYPE_ELEMENT,elementId,elementId,(fsignature+SIGN_ELEMENT),fdoc,r.getOffset()+prevlocator.getColumnNumber()-1,0); - currentElement.setName(elementName); - if ( isUseIdMap() && idMap.containsKey(fsignature)) - currentElement.setUsesIDMAP(true); - if (fOrdered != null && fOrdered.contains(parentSig)) - currentElement.setIsOrderedChild(true); - - fcurrentParent.addChild(currentElement); - currentElement.setParent(fcurrentParent); - fcurrentParent = currentElement; - if (XMLStructureCreator.DEBUG_MODE) System.out.println("\nAdded Element " + raw + " with offset " + r.getOffset()); //$NON-NLS-2$ //$NON-NLS-1$ - if (XMLStructureCreator.DEBUG_MODE) System.out.println("fcurrentParent1: " + fcurrentParent.getId()); //$NON-NLS-1$ - - if (attrs != null) { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("attrs != null, fcurrentParent is " + fcurrentParent.getId()); //$NON-NLS-1$ - //attrs = sortAttributes(attrs); - int len = attrs.getLength(); - int element_lines_length_size; - int[] element_lines_length; - int column_offset; - String element_string; - if (fcurrentParent.getParent().getId().equals(ROOT_ID)) { - element_lines_length_size = locator.getLineNumber()-prevlocator.getLineNumber(); - element_lines_length = new int[element_lines_length_size]; - column_offset = 0; - element_string = ""; //$NON-NLS-1$ - for (int i_ell=0; i_ell<element_lines_length.length; i_ell++) { - IRegion attr_r = fdoc.getLineInformation(i_ell+prevlocator.getLineNumber()); - element_lines_length[i_ell] = fdoc.get(attr_r.getOffset(), attr_r.getLength()).length()+1; - element_string = element_string + fdoc.get(attr_r.getOffset(), attr_r.getLength()) + " "; //$NON-NLS-1$ - } - } else { - element_lines_length_size = locator.getLineNumber()-prevlocator.getLineNumber()+1; - //if (element_lines_length_size < 1) element_lines_length_size = 1; - element_lines_length = new int[element_lines_length_size]; - IRegion first_line = fdoc.getLineInformation(prevlocator.getLineNumber()-1); - column_offset = prevlocator.getColumnNumber()-1; - int first_line_relevant_offset = first_line.getOffset()+column_offset; - int first_line_relevant_length = first_line.getLength()-column_offset; - element_string = fdoc.get(first_line_relevant_offset, first_line_relevant_length) + " "; //$NON-NLS-1$ - element_lines_length[0] = element_string.length(); - for (int i_ell=1; i_ell<element_lines_length.length; i_ell++) { - IRegion attr_r = fdoc.getLineInformation(i_ell+prevlocator.getLineNumber()-1); - element_lines_length[i_ell] = fdoc.get(attr_r.getOffset(), attr_r.getLength()).length()+1; - element_string = element_string + fdoc.get(attr_r.getOffset(), attr_r.getLength()) + " "; //$NON-NLS-1$ - } - } - - for (int i_attr = 0; i_attr < len; i_attr++) { - String attr_name = attrs.getQName(i_attr); - String attr_value = attrs.getValue(i_attr); - - /* find range of attribute in doc; manually parses the line */ - boolean found = false; - int first_quotes = -1; - int second_quotes = -1; - int id_index = -1; - while (!found) { - first_quotes = element_string.indexOf("\"",second_quotes+1); //$NON-NLS-1$ - second_quotes = element_string.indexOf("\"",first_quotes+1); //$NON-NLS-1$ - String value; - try { - value = element_string.substring(first_quotes+1,second_quotes); - } catch (Exception e) { - value = ""; //$NON-NLS-1$ - } - if (value.equals("")) //$NON-NLS-1$ - found = true; - else if (value.equals(attr_value)) { - id_index = element_string.lastIndexOf(attr_name,first_quotes-1); - boolean wrong = false; - boolean found_equal = false; - for (int i_char=id_index+attr_name.length(); i_char<first_quotes && !wrong; i_char++) { - if (element_string.charAt(i_char) == '=') - if (!found_equal) - found_equal = true; - else - wrong = true; - else if (!Character.isWhitespace(element_string.charAt(i_char))) - wrong = true; - } - if (!wrong) found = true; - } - } - //id_index has one char missing for every line (the final cr) - int line_of_index = 0; - for (line_of_index = 0; id_index > element_lines_length[line_of_index]-1; line_of_index++) - id_index -= (element_lines_length[line_of_index]); - if (line_of_index == 0) id_index += column_offset; - if (fcurrentParent.getParent().getId().equals(ROOT_ID)) - line_of_index += prevlocator.getLineNumber(); - else - line_of_index += prevlocator.getLineNumber()-1; - //index at line line_of_index, line offset id_index - int line_of_end_of_value = 0; - int end_of_value_index = second_quotes; - for (line_of_end_of_value = 0; end_of_value_index > element_lines_length[line_of_end_of_value]-1; line_of_end_of_value++) - end_of_value_index -= (element_lines_length[line_of_end_of_value]); - if (line_of_end_of_value == 0) end_of_value_index += column_offset; - if (fcurrentParent.getParent().getId().equals(ROOT_ID)) - line_of_end_of_value += prevlocator.getLineNumber(); - else - line_of_end_of_value += prevlocator.getLineNumber()-1; - //end of value at line line_of_end_of_value, line offset end_of_value_index - - int attr_start_doc_offset = fdoc.getLineInformation(line_of_index).getOffset()+id_index; - //int attr_length_doc_offset = fdoc.getLineInformation(line_of_value).getOffset()+value_index+attr_value.length()+1+(line_of_end_of_value-line_of_index) - attr_start_doc_offset; - int attr_length_doc_offset = fdoc.getLineInformation(line_of_end_of_value).getOffset()+end_of_value_index +1 - attr_start_doc_offset; - currentElement = new XMLNode(TYPE_ATTRIBUTE,attr_name,attr_value,(fsignature+attr_name+SIGN_SEPARATOR+SIGN_ATTRIBUTE),fdoc,attr_start_doc_offset,attr_length_doc_offset); - currentElement.setName(attr_name); - fcurrentParent.addChild(currentElement); - currentElement.setParent(fcurrentParent); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("added attribute " + currentElement.getId() + " with value >" + currentElement.getValue() + "<" + " to element " + fcurrentParent.getId() + " which has parent " + fcurrentParent.getParent().getId()); //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - } - } - } catch (BadLocationException ex) { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("BadLocationException in startElement(...) " + ex); //$NON-NLS-1$ - currentElement = new XMLChildren(TYPE_ELEMENT,raw+"_("+((XMLChildren)fcurrentParent).children+")",raw+"_("+((XMLChildren)fcurrentParent).children+")",(fsignature+SIGN_ELEMENT),fdoc,0,0); //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - } - if (XMLStructureCreator.DEBUG_MODE) System.out.println("At the end of startElement(...), fcurrentParent is " + fcurrentParent.getId()); //$NON-NLS-1$ - prevlocator = new LocatorImpl(locator); - } // startElement(String,String,String,Attributes) - - /** Characters. */ - public void characters(char ch[], int start, int length) { - if (!ignoreBodies) { -// String chars = (new String(ch, start, length)).trim(); - String chars= new String(ch, start, length); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("characters: >" + chars + "<"); //$NON-NLS-2$ //$NON-NLS-1$ - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Body Location: line " + locator.getLineNumber() + " column " + locator.getColumnNumber()); //$NON-NLS-2$ //$NON-NLS-1$ - - //if text contains only white space, it will be ignored. - if (!trimWhiteSpace(chars).equals("")) { //$NON-NLS-1$ - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Adding body"); //$NON-NLS-1$ - try { - IRegion r= fdoc.getLineInformation(locator.getLineNumber()-1); - //location returns the END of the characters - //offset of BEGINNING of characters: - int offset = r.getOffset()+locator.getColumnNumber()-1-length; - fcurrentParent.bodies++; - String body_value = new String(ch, start, length); - if (fRemoveWhiteSpace) { - body_value= removeWhiteSpace(body_value); - } - XMLNode bodynode = new XMLNode(TYPE_TEXT,"body_("+fcurrentParent.bodies+")",body_value,(fsignature+SIGN_TEXT),fdoc,offset,length); //$NON-NLS-2$ //$NON-NLS-1$ - bodynode.setName(MessageFormat.format("{0} ({1})",new String[] {XMLCompareMessages.getString("XMLStructureCreator.body"),Integer.toString(fcurrentParent.bodies)})); //$NON-NLS-2$ //$NON-NLS-1$ - fcurrentParent.addChild(bodynode); - bodynode.setParent(fcurrentParent); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Created body " + fcurrentParent.bodies //$NON-NLS-1$ - + " with offset " + offset + " and length " + length //$NON-NLS-2$ //$NON-NLS-1$ - + " with parent " + bodynode.getParent().getId()); //$NON-NLS-1$ - //bodies as id attributes - String popsig = fcurrentParent.getParent().getSignature(); //signature of parent of parent - popsig = popsig.substring(0,popsig.lastIndexOf(SIGN_ELEMENT)); - if (isUseIdMap() && fcurrentParent.bodies == 1 && idMap.containsKey(popsig)) { - String pid= fcurrentParent.getId();//id of parent - String pelementname= pid.substring(0,pid.indexOf("<"));//name of parent element //$NON-NLS-1$ - if ( ((String)idMap.get(popsig)).equals(ID_TYPE_BODY+pelementname) ) { - XMLNode pop= fcurrentParent.getParent(); - String popid= pop.getId(); - String popelementname= popid.substring(0,popid.indexOf("<")); //$NON-NLS-1$ - pop.setId(popelementname + "<" + body_value); //$NON-NLS-1$ - pop.setOrigId(popelementname + "<" + body_value); //$NON-NLS-1$ - pop.setName(MessageFormat.format("{0} [{1}={2}]",new String[] {popelementname, pelementname, body_value})); //$NON-NLS-1$ - pop.setUsesIDMAP(true); - } - } - } catch (BadLocationException ex) { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("BadLocationException in characters(...) " + ex); //$NON-NLS-1$ - fcurrentParent.addChild(new XMLNode(TYPE_TEXT,"body_("+fcurrentParent.bodies+")",new String(ch, start, length),(fsignature+SIGN_TEXT),fdoc,0,0)); //$NON-NLS-2$ //$NON-NLS-1$ - } - } - } - prevlocator = new LocatorImpl(locator); - } // characters(char[],int,int); - - /** Ignorable whitespace. */ - public void ignorableWhitespace(char ch[], int start, int length) { -// -//// characters(ch, start, length); -//// System.out.flush(); -// - prevlocator = new LocatorImpl(locator); - } // ignorableWhitespace(char[],int,int); - - /** End element. */ - public void endElement(String uri, String local, String raw) { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("\nExiting element " + fcurrentParent.getId()); //$NON-NLS-1$ - - if (XMLStructureCreator.DEBUG_MODE) System.out.println("prevlocator: line " + prevlocator.getLineNumber() + " column " + prevlocator.getColumnNumber() + " id " + prevlocator.getPublicId()); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - if (XMLStructureCreator.DEBUG_MODE) System.out.println("locator: line " + locator.getLineNumber() + " column " + locator.getColumnNumber() + " id " + locator.getPublicId()); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - - - if (fcurrentParent.getParent() != null) { - try { - IRegion r2= fdoc.getLineInformation(locator.getLineNumber()-1); - Position pos = fcurrentParent.getRange(); - - int elem_length = r2.getOffset()+locator.getColumnNumber()-1 - pos.getOffset();//length of element from start tag to end tag - fcurrentParent.setLength(elem_length); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("pos.getOffset: " + pos.getOffset() + " elem_length: " + elem_length); //$NON-NLS-2$ //$NON-NLS-1$ - if (XMLStructureCreator.DEBUG_MODE) System.out.println("fdoc.get(pos.getOffset()+elem_length-5,4): >" + fdoc.get(pos.getOffset()+elem_length-5,4) + "<"); //$NON-NLS-2$ //$NON-NLS-1$ - //if (fdoc.get(pos.getOffset()+elem_length-2,1) != ">") elem_length-=1; - try { - fcurrentParent.setValue(fdoc.get(pos.getOffset(),elem_length)); - } catch (BadLocationException ex) { - try { - fcurrentParent.setValue(fdoc.get(pos.getOffset(),elem_length-1)); - } catch (BadLocationException ex2) { - if (XMLStructureCreator.DEBUG_MODE) { - System.out.println("BadLocationException in endElement(...) while attempting fcurrentParent.setValue(...): " + ex); //$NON-NLS-1$ - System.out.println("Attempt to correct BadLocationException failed: " + ex2); //$NON-NLS-1$ - } - } - } - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Value of " + fcurrentParent.getId() + " is >" + fcurrentParent.getValue() + "<"); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - - //going from ending element to parent element - fcurrentParent = fcurrentParent.getParent(); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("fcurrentParent = fcurrentParent.getParent();"); //$NON-NLS-1$ - } catch (BadLocationException ex) { - if (XMLStructureCreator.DEBUG_MODE) { - System.out.println("BadLocationException in endElement(...): " + ex); //$NON-NLS-1$ - System.out.println("fcurrentParent.getId(): " + fcurrentParent.getId()); //$NON-NLS-1$ - } - } - } else { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Error: Cannot reach Parent of Parent"); //$NON-NLS-1$ - } - if (XMLStructureCreator.DEBUG_MODE) System.out.println("fcurrentParent is now " + fcurrentParent.getId()); //$NON-NLS-1$ - - prevlocator = new LocatorImpl(locator); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Signature before cutting: " + fsignature); //$NON-NLS-1$ - int ssi = fsignature.lastIndexOf(SIGN_SEPARATOR);//fsignature separator index - ssi = fsignature.lastIndexOf(SIGN_SEPARATOR,ssi-1);//second-last ".", e.g. in root.a.b. to obtain root.a. - fsignature = fsignature.substring(0,ssi+1); - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Signature after cutting: " + fsignature); //$NON-NLS-1$ - } // endElement(String) - - // - // ErrorHandler methods - // - - /** Warning. */ - public void warning(SAXParseException ex) { - System.err.println("[Warning] "+ //$NON-NLS-1$ - getLocationString(ex)+": "+ //$NON-NLS-1$ - ex.getMessage()); - } - - /** Error. */ - public void error(SAXParseException ex) { - System.err.println("[Error] "+ //$NON-NLS-1$ - getLocationString(ex)+": "+ //$NON-NLS-1$ - ex.getMessage()); - } - - /** Fatal error. */ - public void fatalError(SAXParseException ex) throws SAXException { - System.err.println("[Fatal Error] "+ //$NON-NLS-1$ - getLocationString(ex)+": "+ //$NON-NLS-1$ - ex.getMessage()); - //System.out.println(ex); - //throw ex; - } - - /** Returns a string of the location. */ - private String getLocationString(SAXParseException ex) { - StringBuffer str = new StringBuffer(); - - String systemId = ex.getSystemId(); - if (systemId != null) { - int index = systemId.lastIndexOf('/'); - if (index != -1) - systemId = systemId.substring(index + 1); - str.append(systemId); - } - str.append(':'); - str.append(ex.getLineNumber()); - str.append(':'); - str.append(ex.getColumnNumber()); - - return str.toString(); - - } // getLocationString(SAXParseException):String - - } - - public XMLStructureCreator() { - //set default idmap - fIdMapToUse= DEFAULT_IDMAP; - fUseIdMap= false; - XMLPlugin plugin= XMLPlugin.getDefault(); - //if statement required for tests - if (plugin != null) { - fIdMaps = plugin.getIdMaps(); - fIdMapsInternal = plugin.getIdMapsInternal(); - fIdExtensionToName = plugin.getIdExtensionToName(); - fOrderedElements= plugin.getOrderedElements(); - fOrderedElementsInternal= plugin.getOrderedElementsInternal(); - } - fRemoveWhiteSpace= false; - } - -// public void setNameScheme(String idmap_name) { -// fName = MessageFormat.format("{0} ({1})", new String[] {DEFAULT_NAME,idmap_name}); //$NON-NLS-1$ -// } -// - /** - * This title will be shown in the title bar of the structure compare pane. - */ - public String getName() { - return DEFAULT_NAME; - } - - /** - * Set File extension of the parsed file. This extension will be used to choose an Id Map scheme. - */ - public void setFileExtension(String ext) { - fFileExt= ext; - } - - /** - * Initialize the Id Mappings for the Id Mapping Scheme and the Ordered Elements - * This method must be called before getStructure(Object) is called on the two/three inputs of the compare - */ - public void initIdMaps() { - if (fFirstCall && fFileExt != null) { - fFirstCall = false; - String fileExtLower= fFileExt.toLowerCase(); - if (fIdExtensionToName.containsKey(fileExtLower)) - setIdMap((String)fIdExtensionToName.get(fileExtLower)); - } - - setUseIdMap(); - fOrdered= null; - if (!isUseIdMap()) - idMap = null; - else if (fIdMaps.containsKey(fIdMapToUse)) { - idMap = (HashMap) fIdMaps.get(fIdMapToUse); - } else if (fIdMapsInternal.containsKey(fIdMapToUse)) { - idMap = (HashMap) fIdMapsInternal.get(fIdMapToUse); - } - - if (fOrderedElements != null) - fOrdered= (ArrayList) fOrderedElements.get(fIdMapToUse); - if (fOrdered == null && fOrderedElementsInternal != null) - fOrdered= (ArrayList) fOrderedElementsInternal.get(fIdMapToUse); - } - - /** - * Returns the XML parse tree of the input. - */ - public IStructureComparator getStructure(Object input) { - if (XMLStructureCreator.DEBUG_MODE) System.out.println("Starting parse"); //$NON-NLS-1$ - - if (!(input instanceof IStreamContentAccessor)) - return null; - - IStreamContentAccessor sca= (IStreamContentAccessor) input; - - try { - - //Input parsed with parser.parse(new InputSource(sca.getContents)); - String contents= readString(sca.getContents()); - if (contents == null) - contents= ""; //$NON-NLS-1$ - - fdoc= new Document(contents); - fsignature = ROOT_ID + SIGN_SEPARATOR; - XMLChildren root= new XMLChildren(TYPE_ELEMENT,ROOT_ID, "",(fsignature+SIGN_ELEMENT), fdoc, 0, fdoc.getLength()); //$NON-NLS-1$ - fcurrentParent = root; - - XMLHandler handler = new XMLHandler(); - - try { -// /* original xerces code -// SAXParser parser = (SAXParser)Class.forName(parserName).newInstance(); -// */ -// XMLReader parser = XMLReaderFactory.createXMLReader(parserName); -// -// parser.setFeature( "http://xml.org/sax/features/validation", setValidation); //$NON-NLS-1$ -// parser.setFeature( "http://xml.org/sax/features/namespaces", setNameSpaces ); //$NON-NLS-1$ -// /* -// parser.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false); //$NON-NLS-1$ -// parser.setFeature( "http://apache.org/xml/features/validation/schema", setSchemaSupport ); //$NON-NLS-1$ -// parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", setSchemaFullSupport); //$NON-NLS-1$ -// */ -// parser.setContentHandler(handler); -// parser.setErrorHandler(handler); -// -// parser.parse(new InputSource(sca.getContents())); - - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(true); - SAXParser parser = factory.newSAXParser(); - parser.parse(new InputSource(sca.getContents()), handler); - - if (XMLStructureCreator.DEBUG_MODE) System.out.println("End of parse"); //$NON-NLS-1$ - } catch (SAXParseException e) { - XMLPlugin.log(e); - return null; - } catch (Exception e) { -// MessageDialog.openError(XMLPlugin.getActiveWorkbenchShell(),"Error in XML parser","An error occured in the XML parser.\nNo structured compare can be shown"); - XMLPlugin.log(e); - return null; - } - - return root; - } catch (CoreException ex) { - XMLPlugin.log(ex); - } - return null; - } - - public boolean canSave() { - return true; - } - - public boolean canRewriteTree() { - return false; - } - - public void rewriteTree(Differencer differencer, IDiffContainer root) { - } - - public void save(IStructureComparator structure, Object input) { - if (input instanceof IEditableContent && structure instanceof XMLNode) { - IDocument doc= ((XMLNode)structure).getDocument(); - IEditableContent bca= (IEditableContent) input; - String c= doc.get(); - bca.setContent(c.getBytes()); - } - } - - public String getContents(Object node, boolean ignoreWhitespace) { - if (node instanceof XMLNode) { - String s= ((XMLNode)node).getValue(); - if (ignoreWhitespace) - s= s.trim(); - return s; - } - return null; - } - - public IStructureComparator locate(Object path, Object source) { - return null; - } - - /** - * Returns null if an error occurred. - */ - static String readString(InputStream is) { - if (is == null) - return null; - BufferedReader reader= null; - try { - StringBuffer buffer= new StringBuffer(); - char[] part= new char[2048]; - int read= 0; - reader= new BufferedReader(new InputStreamReader(is)); - - while ((read= reader.read(part)) != -1) - buffer.append(part, 0, read); - - return buffer.toString(); - - } catch (IOException ex) { - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException ex) { - } - } - } - return null; - } - - /** Returns a sorted list of attributes. */ - /* Taken from SAX2Writer sample of xerces */ - protected Attributes sortAttributes(Attributes attrs) { - - AttributesImpl attributes = new AttributesImpl(); - int len = (attrs != null) ? attrs.getLength() : 0; - for (int i = 0; i < len; i++) { - String name = attrs.getQName(i); - int count = attributes.getLength(); - int j = 0; - while (j < count) { - if (name.compareTo(attributes.getQName(j)) < 0) { - break; - } - j++; - } - attributes.insertAttributeAt(j, name, attrs.getType(i), - attrs.getValue(i)); - } - - return attributes; - - } // sortAttributes(AttributeList):AttributeList - - public void setIdMap(String idmap_name) { - fIdMapToUse= idmap_name; - } - - /** Returns the name of the IdMap Scheme that will be used to set ids. - */ - public String getIdMap() { - return fIdMapToUse; - } - - public void setUseIdMap() { - if (fIdMaps != null && fIdMapsInternal != null) - fUseIdMap= fIdMaps.containsKey(fIdMapToUse) || fIdMapsInternal.containsKey(fIdMapToUse); - } - - public boolean isUseIdMap() { - return fUseIdMap; - } - - public void updateIdMaps() { - fIdMaps = XMLPlugin.getDefault().getIdMaps(); - fOrderedElements= XMLPlugin.getDefault().getOrderedElements(); - } - - protected boolean isWhiteSpace(char c) { - return c == '\t' || c == '\n' || c == '\r' || c == ' '; - } - - protected String removeWhiteSpace(String str) { - str= trimWhiteSpace(str); - StringBuffer retStr= new StringBuffer(); - int start= 0, end= 0; - outer_while: - while (true) { - while ( end < str.length() && !isWhiteSpace(str.charAt(end)) ) { end++; } - if (end > str.length()) break outer_while; - if ( start != 0) retStr.append(' '); - retStr.append(str.substring(start, end)); - end++; - while ( end < str.length() && isWhiteSpace(str.charAt(end)) ) { end++; } - start= end; - } - return retStr.toString(); - } - - protected String trimWhiteSpace(String str) { - int start=0, end= str.length()-1; - while (start < str.length() && isWhiteSpace(str.charAt(start))) { start++; } - if ( start == str.length() ) - return ""; //$NON-NLS-1$ - while (end >= 0 && isWhiteSpace(str.charAt(end))) { end--; } - return str.substring(start, end+1); - } - - public void setRemoveWhiteSpace(boolean removeWhiteSpace) { - fRemoveWhiteSpace= removeWhiteSpace; - } - - public boolean getRemoveWhiteSpace() { - return fRemoveWhiteSpace; - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java deleted file mode 100644 index f67caca84..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java +++ /dev/null @@ -1,608 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import java.lang.reflect.InvocationTargetException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.compare.CompareViewerSwitchingPane; -import org.eclipse.compare.ITypedElement; -import org.eclipse.compare.internal.TimeoutContext; -import org.eclipse.compare.structuremergeviewer.DiffNode; -import org.eclipse.compare.structuremergeviewer.ICompareInput; -import org.eclipse.compare.structuremergeviewer.IStructureComparator; -import org.eclipse.compare.structuremergeviewer.StructureDiffViewer; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Tree; - -/** - * An XML diff tree viewer that can be configured with a <code>IStructureCreator</code> - * to retrieve a hierarchical structure from the input object (an <code>ICompareInput</code>) - * and perform a two-way or three-way compare on it. - * <p> - * This class may be instantiated; it is not intended to be subclassed outside - * this package. - * </p> - * - * @see IStructureCreator - * @see ICompareInput - */ -public class XMLStructureViewer extends StructureDiffViewer { - - private CompareViewerSwitchingPane fParent; - - private HashMap fIdMapsInternal; - private HashMap fIdMaps; - private HashMap fOrderedElementsInternal; - private HashMap fOrderedElements; - - protected static final char SIGN_SEPARATOR= - XMLStructureCreator.SIGN_SEPARATOR; - - /** - * Creates a new viewer for the given SWT tree control with the specified configuration. - * - * @param tree the tree control - * @param configuration the configuration for this viewer - */ - class XMLSorter extends ViewerSorter { - - ArrayList fOrdered; - boolean fAlwaysOrderSort; - - public XMLSorter() { - super(); - fAlwaysOrderSort= false; - } - - public void setOrdered(ArrayList ordered) { - fOrdered= ordered; - } - - public void setAlwaysOrderSort(boolean alwaysOrderSort) { - fAlwaysOrderSort= alwaysOrderSort; - } - - public int category(Object node) { - if (node instanceof DiffNode) { - Object o= ((DiffNode) node).getId(); - if (o instanceof XMLNode) { - String xmlType= ((XMLNode) o).getXMLType(); - if (xmlType.equals(XMLStructureCreator.TYPE_ATTRIBUTE)) - return 1; - if (xmlType.equals(XMLStructureCreator.TYPE_ELEMENT)) - return 2; - if (xmlType.equals(XMLStructureCreator.TYPE_TEXT)) - return 2; - } - } - return 0; - } - - public void sort(final Viewer viewer, Object[] elements) { - if ((fOrdered != null || fAlwaysOrderSort) - && elements != null - && elements.length > 0 - && elements[0] instanceof DiffNode) { - Object o= ((DiffNode) elements[0]).getId(); - if (o instanceof XMLNode) { - XMLNode parent= ((XMLNode) o).getParent(); - String sig= parent.getSignature(); - if (sig.endsWith(XMLStructureCreator.SIGN_ELEMENT)) { - String newSig= - sig.substring( - 0, - sig.length() - - XMLStructureCreator.SIGN_ELEMENT.length()); - if (fAlwaysOrderSort || fOrdered.contains(newSig)) { - final ArrayList originalTree= - new ArrayList( - Arrays.asList(parent.getChildren())); - Arrays.sort(elements, new Comparator() { - public int compare(Object a, Object b) { - return XMLSorter.this.compare( - (DiffNode) a, - (DiffNode) b, - originalTree); - } - }); - return; - } - } - } - } - super.sort(viewer, elements); - } - - private int compare(DiffNode a, DiffNode b, ArrayList originalTree) { - - int index_a= originalTree.indexOf(a.getId()); - int index_b= originalTree.indexOf(b.getId()); - if (index_a < index_b) - return -1; - else - return 1; - } - } - - public XMLStructureViewer(Tree tree, CompareConfiguration configuration) { - super(tree, configuration); - initialize(); - } - - /** - * Creates a new viewer under the given SWT parent with the specified configuration. - * - * @param parent the SWT control under which to create the viewer - * @param configuration the configuration for this viewer - */ - public XMLStructureViewer( - Composite parent, - CompareConfiguration configuration) { - super(parent, configuration); - if (parent instanceof CompareViewerSwitchingPane) { - fParent= (CompareViewerSwitchingPane) parent; - } - initialize(); - } - - private void initialize() { - setStructureCreator(new XMLStructureCreator()); - XMLPlugin plugin= XMLPlugin.getDefault(); - - plugin.getViewers().add(this); - - fIdMaps= plugin.getIdMaps(); - fIdMapsInternal= plugin.getIdMapsInternal(); - fOrderedElements= plugin.getOrderedElements(); - fOrderedElementsInternal= plugin.getOrderedElementsInternal(); - - XMLSorter sorter= new XMLSorter(); - setSorter(sorter); - - } - - protected XMLStructureCreator getXMLStructureCreator() { - return (XMLStructureCreator) getStructureCreator(); - } - - /* (non Javadoc) - * Overridden to unregister all listeners. - */ - protected void handleDispose(DisposeEvent event) { - - XMLPlugin.getDefault().getViewers().remove(this); - - super.handleDispose(event); - } - - /** - * Recreates the comparable structures for the input sides. - */ - protected void compareInputChanged(ICompareInput input) { - if (input != null) { - ITypedElement t= input.getLeft(); - if (t != null) { - String fileExtension= t.getType(); - getXMLStructureCreator().setFileExtension(fileExtension); - } - } - - getXMLStructureCreator().initIdMaps(); - super.compareInputChanged(input); - - if (input != null && fParent.getTitleArgument() == null) - appendToTitle(getXMLStructureCreator().getIdMap()); - } - - /** - * Calls <code>diff</code> whenever the byte contents changes. - */ - protected void contentChanged() { - fIdMaps= XMLPlugin.getDefault().getIdMaps(); - fOrderedElements= XMLPlugin.getDefault().getOrderedElements(); - getXMLStructureCreator().updateIdMaps(); - if (isIdMapRemoved()) { - getXMLStructureCreator().setIdMap( - XMLStructureCreator.DEFAULT_IDMAP); - } - - getXMLStructureCreator().initIdMaps(); - - contentChanged(null); - - if (fParent.getTitleArgument() == null) - appendToTitle(getXMLStructureCreator().getIdMap()); - - } - - public IRunnableWithProgress getMatchingRunnable( - final XMLNode left, - final XMLNode right, - final XMLNode ancestor) { - return new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) - throws - InvocationTargetException, - InterruptedException, - OperationCanceledException { - if (monitor == null) { - monitor= new NullProgressMonitor(); - } - int totalWork; - if (ancestor != null) - totalWork= 1; - else - totalWork= 3; - monitor.beginTask(XMLCompareMessages.getString("XMLStructureViewer.matching.beginTask"), totalWork); //$NON-NLS-1$ - ArrayList ordered= null; - if (!getXMLStructureCreator() - .getIdMap() - .equals(XMLStructureCreator.USE_UNORDERED) - && !getXMLStructureCreator().getIdMap().equals( - XMLStructureCreator.USE_ORDERED)) { - ordered= - (ArrayList) fOrderedElements.get( - getXMLStructureCreator().getIdMap()); - if (ordered == null) - ordered= - (ArrayList) fOrderedElementsInternal.get( - getXMLStructureCreator().getIdMap()); - } - if (getSorter() instanceof XMLSorter) - ((XMLSorter) getSorter()).setOrdered(ordered); - AbstractMatching m; - if (getXMLStructureCreator() - .getIdMap() - .equals(XMLStructureCreator.USE_ORDERED)) { - m= new OrderedMatching(); - if (getSorter() instanceof XMLSorter) - ((XMLSorter) getSorter()).setAlwaysOrderSort(true); - } else { - m= new GeneralMatching(ordered); - if (getSorter() instanceof XMLSorter) - ((XMLSorter) getSorter()).setAlwaysOrderSort(false); - } - try { - m.match(left, right, false, monitor); - if (ancestor != null) { - m.match( - left, - ancestor, - true, - new SubProgressMonitor(monitor, 1)); - m.match( - right, - ancestor, - true, - new SubProgressMonitor(monitor, 1)); - } - // } catch (InterruptedException e) { - // System.out.println("in run"); - // e.printStackTrace(); - } finally { - monitor.done(); - } - } - }; - } - - protected void preDiffHook( - IStructureComparator ancestor, - IStructureComparator left, - IStructureComparator right) { - // if (!xsc.getIdMap().equals(XMLStructureCreator.USE_ORDERED)) { - //TimeoutContext.run(true, TIMEOUT, getControl().getShell(), runnable); - if (left != null && right != null) { - try { - TimeoutContext.run( - true, - 500, - XMLPlugin.getActiveWorkbenchShell(), - getMatchingRunnable( - (XMLNode) left, - (XMLNode) right, - (XMLNode) ancestor)); - } catch (Exception e) { - XMLPlugin.log(e); - } - } - } - - /** - * Overriden to create buttons in the viewer's pane control bar. - * <p> - * - * @param toolbarManager the toolbar manager for which to add the buttons - */ - protected void createToolItems(ToolBarManager toolBarManager) { - super.createToolItems(toolBarManager); - toolBarManager.appendToGroup("modes", new ChooseMatcherDropDownAction(this)); //$NON-NLS-1$ - toolBarManager.appendToGroup("modes", new CreateNewIdMapAction(this)); //$NON-NLS-1$ - } - - /** - * Overriden to create a context menu. - * <p> - * - * @param manager the menu manager for which to add menu items - */ - protected void fillContextMenu(IMenuManager manager) { - super.fillContextMenu(manager); - ISelection s= getSelection(); - if (s instanceof StructuredSelection - && ((StructuredSelection) s).getFirstElement() instanceof DiffNode - && ((DiffNode) ((StructuredSelection) s).getFirstElement()).getId() - instanceof XMLNode) { - DiffNode diffnode= - (DiffNode) ((StructuredSelection) s).getFirstElement(); - String diffnodeIdSig= ((XMLNode) diffnode.getId()).getSignature(); - fIdMaps= XMLPlugin.getDefault().getIdMaps(); - String idmap_name= getXMLStructureCreator().getIdMap(); - if (diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_ATTRIBUTE) || (diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_TEXT) && ((XMLNode) diffnode.getId()).getOrigId().endsWith("(1)"))) { //$NON-NLS-1$ - Action action= new SetAsIdAction(diffnode); - if (!fIdMaps.containsKey(idmap_name)) { - action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.notUserIdMap")); //$NON-NLS-1$ - action.setEnabled(false); - } else { - HashMap idmapHM= (HashMap) fIdMaps.get(idmap_name); - XMLNode idNode= (XMLNode) diffnode.getId(); - String signature= idNode.getSignature(); - String idname= ""; //$NON-NLS-1$ - if (idNode - .getSignature() - .endsWith(XMLStructureCreator.SIGN_ATTRIBUTE)) { - signature= - signature.substring( - 0, - signature.indexOf( - XMLStructureCreator.SIGN_ATTRIBUTE)); - int end_of_signature= - signature.lastIndexOf( - SIGN_SEPARATOR, - signature.length() - 2); - idname= - signature.substring( - end_of_signature + 1, - signature.length() - 1); - signature= signature.substring(0, end_of_signature + 1); - } else if ( - idNode.getSignature().endsWith( - XMLStructureCreator.SIGN_TEXT)) { - XMLNode textNode= (XMLNode) diffnode.getId(); - XMLNode idelem= textNode.getParent(); - XMLNode elem= idelem.getParent(); - signature= - elem.getSignature().substring( - 0, - elem.getSignature().indexOf( - XMLStructureCreator.SIGN_ELEMENT)); - idname= idelem.getOrigId(); - idname= - idname.substring( - 0, - idname.indexOf( - XMLStructureCreator.ID_SEPARATOR)); - idname= - new Character(XMLStructureCreator.ID_TYPE_BODY) - + idname; - } - if (idmapHM.containsKey(signature)) { - if (idmapHM.get(signature).equals(idname)) { - action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.setId.text1")); //$NON-NLS-1$ - action.setEnabled(false); - } else { - String oldId= (String) idmapHM.get(signature); - if (oldId - .startsWith( - (new Character(XMLStructureCreator - .ID_TYPE_BODY)) - .toString())) - oldId= oldId.substring(1); - action.setText(MessageFormat.format("{0} {1}", new String[] { XMLCompareMessages.getString("XMLStructureViewer.action.setId.text2"), oldId })); //$NON-NLS-2$ //$NON-NLS-1$ - action.setEnabled(true); - } - } else { - action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.setId.text3")); //$NON-NLS-1$ - action.setEnabled(true); - } - } - manager.add(action); - } else if ( - diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_ELEMENT)) { - SetOrderedAction action= new SetOrderedAction(idmap_name); - if (!fIdMaps.containsKey(idmap_name)) { - action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.notUserIdMap")); //$NON-NLS-1$ - action.setEnabled(false); - } else { - ArrayList idmapOrdered= - (ArrayList) fOrderedElements.get(idmap_name); - XMLNode idNode= (XMLNode) diffnode.getId(); - String signature= idNode.getSignature(); - // String idname= ""; - signature= - signature.substring( - 0, - signature.indexOf( - XMLStructureCreator.SIGN_ELEMENT)); - if (idmapOrdered != null - && idmapOrdered.contains(signature)) { - action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.setOrdered.exists")); //$NON-NLS-1$ - action.setEnabled(false); - } else { - action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.setOrdered")); //$NON-NLS-1$ - action.setSignature(signature); - action.setEnabled(true); - } - } - - manager.add(action); - } - } - } - - protected void appendToTitle(String idmap_name) { - if (fParent != null) { - getXMLStructureCreator().setIdMap(idmap_name); - fParent.setTitleArgument(idmap_name); - } - } - - /** - * Returns true if the current Id Map scheme has been removed. - */ - private boolean isIdMapRemoved() { - XMLStructureCreator xsc= getXMLStructureCreator(); - String IdMapName= xsc.getIdMap(); - return !IdMapName.equals(XMLStructureCreator.USE_UNORDERED) - && !IdMapName.equals(XMLStructureCreator.USE_ORDERED) - && !fIdMaps.containsKey(IdMapName) - && !fIdMapsInternal.containsKey(IdMapName) - && !fOrderedElements.containsKey(IdMapName); - } - - protected class SetAsIdAction extends Action { - - DiffNode fDiffNode; - - public SetAsIdAction(DiffNode diffnode) { - fDiffNode= diffnode; - } - - public void run() { - XMLStructureCreator sc= getXMLStructureCreator(); - // DiffNode diffnode = (DiffNode) ((StructuredSelection) getSelection()).getFirstElement(); - String idmap_name= sc.getIdMap(); - if (fIdMaps.containsKey(idmap_name)) { - HashMap idmapHM= (HashMap) fIdMaps.get(idmap_name); - if (((XMLNode) fDiffNode.getId()) - .getSignature() - .endsWith(XMLStructureCreator.SIGN_ATTRIBUTE)) { - XMLNode attrNode= (XMLNode) fDiffNode.getId(); - String signature= attrNode.getSignature(); - signature= - signature.substring( - 0, - signature.indexOf( - XMLStructureCreator.SIGN_ATTRIBUTE)); - int end_of_signature= - signature.lastIndexOf( - SIGN_SEPARATOR, - signature.length() - 2); - String idattr= - signature.substring( - end_of_signature + 1, - signature.length() - 1); - signature= signature.substring(0, end_of_signature + 1); - idmapHM.put(signature, idattr); - XMLPlugin.getDefault().setIdMaps( - fIdMaps, - null, - null, - false); - //contentChanged(); - } else if ( - ((XMLNode) fDiffNode.getId()).getSignature().endsWith( - XMLStructureCreator.SIGN_TEXT)) { - XMLNode textNode= (XMLNode) fDiffNode.getId(); - XMLNode idelem= textNode.getParent(); - XMLNode elem= idelem.getParent(); - String signature= - elem.getSignature().substring( - 0, - elem.getSignature().indexOf( - XMLStructureCreator.SIGN_ELEMENT)); - String idname= idelem.getOrigId(); - idname= - idname.substring( - 0, - idname.indexOf(XMLStructureCreator.ID_SEPARATOR)); - idname= - new Character(XMLStructureCreator.ID_TYPE_BODY) - + idname; - idmapHM.put(signature, idname); - XMLPlugin.getDefault().setIdMaps( - fIdMaps, - null, - null, - false); - //contentChanged(); - } - } - } - } - - protected class SetOrderedAction extends Action { - - String fIdMapName; - String fSignature; - - public SetOrderedAction(String idmap_name) { - fIdMapName= idmap_name; - } - - public void run() { - //String idmap_name= getXMLStructureCreator().getIdMap(); - if (fSignature != null) { - ArrayList idmapOrdered= - (ArrayList) fOrderedElements.get(fIdMapName); - if (idmapOrdered == null) { - idmapOrdered= new ArrayList(); - fOrderedElements.put(fIdMapName, idmapOrdered); - } - idmapOrdered.add(fSignature); - } - } - - public void setSignature(String signature) { - fSignature= signature; - } - } - - protected void updateIdMaps() { - getXMLStructureCreator().updateIdMaps(); - } - - /** - * Tracks property changes of the configuration object. - * Clients may override to track their own property changes. - * In this case they must call the inherited method. - */ - protected void propertyChange(PropertyChangeEvent event) { - String key= event.getProperty(); - if (key.equals(CompareConfiguration.IGNORE_WHITESPACE)) { - getXMLStructureCreator().setRemoveWhiteSpace( - !getXMLStructureCreator().getRemoveWhiteSpace()); - contentChanged(); - } - // else - // super.propertyChange(event); - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewerCreator.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewerCreator.java deleted file mode 100644 index 0dd2aa2a9..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewerCreator.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml; - -import org.eclipse.swt.widgets.Composite; - -import org.eclipse.jface.viewers.Viewer; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.compare.IViewerCreator; - -/** - * A factory object for the <code>TextMergeViewer</code>. - * This indirection is necessary because only objects with a default - * constructor can be created via an extension point - * (this precludes Viewers). - */ -public class XMLStructureViewerCreator implements IViewerCreator { - - public Viewer createViewer(Composite parent, CompareConfiguration mp) { - return new XMLStructureViewer(parent, mp); - } -} diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/MessageLine.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/MessageLine.java deleted file mode 100644 index a609e1f12..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/MessageLine.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml.ui; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; - -/** - * A message line. It distinguishs between "normal" messages and errors. - * Setting an error message hides a currently displayed message until - * <code>clearErrorMessage</code> is called. - */ -public class MessageLine extends CLabel { - - public static final RGB RED= new RGB(200, 0, 0); - private static RGB fgDefaultErrorRGB= RED; - - private String fMessageText; - private String fErrorText; - - private Color fDefaultColor; - private RGB fErrorRGB; - private Color fErrorColor; - - /** - * Creates a new message line as a child of the given parent. - * Error message will be shown in <code>RED</code>. - */ - public MessageLine(Composite parent) { - this(parent, SWT.LEFT); - } - - /** - * Creates a new message line as a child of the parent and with the given SWT stylebits. - * Error message will be shown in <code>RED</code>. - */ - public MessageLine(Composite parent, int style) { - super(parent, style); - fDefaultColor= getForeground(); - fErrorRGB= fgDefaultErrorRGB; - } - - /** - * Creates a new message line as a child of the parent and with the given SWT stylebits. - * Error message will be shown with in the given rgb color. - */ - public MessageLine(Composite parent, int style, RGB errorRGB) { - super(parent, style); - fDefaultColor= getForeground(); - fErrorRGB= errorRGB; - } - - /** - * Clears the currently displayed error message and redisplayes - * the message which was active before the error message was set. - */ - public void clearErrorMessage() { - setErrorMessage(null); - } - - /** - * Clears the currently displayed message. - */ - public void clearMessage() { - setMessage(null); - } - - /** - * Get the currently displayed error text. - * @return The error message. If no error message is displayed <code>null</code> is returned. - */ - public String getErrorMessage() { - return fErrorText; - } - - /** - * Get the currently displayed message. - * @return The message. If no message is displayed <code>null<code> is returned. - */ - public String getMessage() { - return fMessageText; - } - - /** - * Sets the default error color used by all message lines. - * Note: a call to this method only affects newly created MessageLines not existing ones. - */ - public static void setDefaultErrorColor(RGB color) { - fgDefaultErrorRGB= color; - } - - /** - * Display the given error message. A currently displayed message - * is saved and will be redisplayed when the error message is cleared. - */ - public void setErrorMessage(String message) { - fErrorText= message; - - if (message == null) { - setMessage(fMessageText); - } else { - if (fErrorColor == null) { - fErrorColor= new Color(getDisplay(), fErrorRGB); - addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - fErrorColor.dispose(); - } - }); - } - setForeground(fErrorColor); - setText(message); - } - } - - /** - * Set the message text. If the message line currently displays an error, - * the message is stored and will be shown after a call to clearErrorMessage - */ - public void setMessage(String message) { - fMessageText= message; - if (message == null) - message= ""; //$NON-NLS-1$ - if (fErrorText == null) { - setForeground(fDefaultColor); - setText(message); - } - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusDialog.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusDialog.java deleted file mode 100644 index 00f07fb24..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusDialog.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml.ui; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; - -import org.eclipse.core.runtime.IStatus; - -/** - * An abstract base class for dialogs with a status bar and ok/cancel buttons. - * The status message must be passed over as StatusInfo object and can be - * an error, warning or ok. The OK button is enabled or disabled depending - * on the status. - */ -public abstract class StatusDialog extends Dialog { - - private Button fOkButton; - private MessageLine fStatusLine; - private IStatus fLastStatus; - private String fTitle; - private Image fImage; - - /** - * Creates an instane of a status dialog. - */ - public StatusDialog(Shell parent) { - super(parent); - } - - /** - * Specifies whether status line appears to the left of the buttons (default) - * or above them. - * - * @param aboveButtons if <code>true</code> status line is placed above buttons; if - * <code>false</code> to the right - */ - public void setStatusLineAboveButtons(boolean aboveButtons) { - } - - /** - * Update the dialog's status line to reflect the given status. - * It is save to call this method before the dialog has been opened. - */ - protected void updateStatus(IStatus status) { - fLastStatus= status; - if (fStatusLine != null && !fStatusLine.isDisposed()) { - updateButtonsEnableState(status); - StatusUtil.applyToStatusLine(fStatusLine, status); - } - } - - // 1GFCRWW: ITPJUI:ALL - Compile errors in VA/Java - /** - * Returns the last status. - */ - public IStatus getStatus() { - return fLastStatus; - } - - /** - * Updates the status of the ok button to reflect the given status. - * Subclasses may override this method to update additional buttons. - * @param status the status. - */ - protected void updateButtonsEnableState(IStatus status) { - if (fOkButton != null && !fOkButton.isDisposed()) - fOkButton.setEnabled(!status.matches(IStatus.ERROR)); - } - - /* - * @see Window#create(Shell) - */ - protected void configureShell(Shell shell) { - super.configureShell(shell); - if (fTitle != null) - shell.setText(fTitle); - } - - /* - * @see Window#create() - */ - public void create() { - super.create(); - if (fLastStatus != null) { - // policy: dialogs are not allowed to come up with an error message - if (fLastStatus.matches(IStatus.ERROR)) { - StatusInfo status= new StatusInfo(); - status.setError(""); //$NON-NLS-1$ - fLastStatus= status; - } - updateStatus(fLastStatus); - } - } - - /* - * @see Dialog#createButtonsForButtonBar(Composite) - */ - protected void createButtonsForButtonBar(Composite parent) { - fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - /* - * @see Dialog#createButtonBar(Composite) - */ - protected Control createButtonBar(Composite parent) { - Composite composite= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 1; - layout.marginHeight= 0; - layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - fStatusLine= new MessageLine(composite); - fStatusLine.setAlignment(SWT.LEFT); - fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fStatusLine.setMessage(""); //$NON-NLS-1$ - - super.createButtonBar(composite); - return composite; - } - - /** - * Sets the title for this dialog. - * @param title the title. - */ - public void setTitle(String title) { - fTitle= title != null ? title : ""; //$NON-NLS-1$ - Shell shell= getShell(); - if ((shell != null) && !shell.isDisposed()) - shell.setText(fTitle); - } - - /** - * Sets the image for this dialog. - * @param image the image. - */ - public void setImage(Image image) { - fImage= image; - Shell shell= getShell(); - if ((shell != null) && !shell.isDisposed()) - shell.setImage(fImage); - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusInfo.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusInfo.java deleted file mode 100644 index c3b6575c5..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusInfo.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.compare.examples.xml.ui; - -import org.eclipse.core.runtime.IStatus; - -import org.eclipse.jface.util.Assert; - -/** - * A settable IStatus. - * Can be an error, warning, info or ok. For error, info and warning states, - * a message describes the problem. - */ -public class StatusInfo implements IStatus { - - private String fStatusMessage; - private int fSeverity; - - /** - * Creates a status set to OK (no message) - */ - public StatusInfo() { - this(OK, null); - } - - /** - * Creates a status . - * @param severity The status severity: ERROR, WARNING, INFO and OK. - * @param message The message of the status. Applies only for ERROR, - * WARNING and INFO. - */ - public StatusInfo(int severity, String message) { - fStatusMessage= message; - fSeverity= severity; - } - - /** - * Returns if the status' severity is OK. - */ - public boolean isOK() { - return fSeverity == IStatus.OK; - } - - /** - * Returns if the status' severity is WARNING. - */ - public boolean isWarning() { - return fSeverity == IStatus.WARNING; - } - - /** - * Returns if the status' severity is INFO. - */ - public boolean isInfo() { - return fSeverity == IStatus.INFO; - } - - /** - * Returns if the status' severity is ERROR. - */ - public boolean isError() { - return fSeverity == IStatus.ERROR; - } - - /** - * @see IStatus#getMessage - */ - public String getMessage() { - return fStatusMessage; - } - - /** - * Sets the status to ERROR. - * @param The error message (can be empty, but not null) - */ - public void setError(String errorMessage) { - Assert.isNotNull(errorMessage); - fStatusMessage= errorMessage; - fSeverity= IStatus.ERROR; - } - - /** - * Sets the status to WARNING. - * @param The warning message (can be empty, but not null) - */ - public void setWarning(String warningMessage) { - Assert.isNotNull(warningMessage); - fStatusMessage= warningMessage; - fSeverity= IStatus.WARNING; - } - - /** - * Sets the status to INFO. - * @param The info message (can be empty, but not null) - */ - public void setInfo(String infoMessage) { - Assert.isNotNull(infoMessage); - fStatusMessage= infoMessage; - fSeverity= IStatus.INFO; - } - - /** - * Sets the status to OK. - */ - public void setOK() { - fStatusMessage= null; - fSeverity= IStatus.OK; - } - - /* - * @see IStatus#matches(int) - */ - public boolean matches(int severityMask) { - return (fSeverity & severityMask) != 0; - } - - /** - * Returns always <code>false</code>. - * @see IStatus#isMultiStatus() - */ - public boolean isMultiStatus() { - return false; - } - - /* - * @see IStatus#getSeverity() - */ - public int getSeverity() { - return fSeverity; - } - - /* - * @see IStatus#getPlugin() - */ - public String getPlugin() { - return "XMLPlugIn"; //$NON-NLS-1$ - } - - /** - * Returns always <code>null</code>. - * @see IStatus#getException() - */ - public Throwable getException() { - return null; - } - - /** - * Returns always the error severity. - * @see IStatus#getCode() - */ - public int getCode() { - return fSeverity; - } - - /** - * Returns always <code>null</code>. - * @see IStatus#getChildren() - */ - public IStatus[] getChildren() { - return new IStatus[0]; - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusUtil.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusUtil.java deleted file mode 100644 index 4de9644ab..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusUtil.java +++ /dev/null @@ -1 +0,0 @@ -/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.compare.examples.xml.ui;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.core.runtime.IStatus;
/**
* A utility class to work with IStatus.
*/
public class StatusUtil {
/**
* Compares two instances of <code>IStatus</code>. The more severe is returned:
* An error is more severe than a warning, and a warning is more severe
* than ok. If the two stati have the same severity, the second is returned.
*/
public static IStatus getMoreSevere(IStatus s1, IStatus s2) {
if (s1.getSeverity() > s2.getSeverity()) {
return s1;
} else {
return s2;
}
}
/**
* Finds the most severe status from a array of stati.
* An error is more severe than a warning, and a warning is more severe
* than ok.
*/
public static IStatus getMostSevere(IStatus[] status) {
IStatus max= null;
for (int i= 0; i < status.length; i++) {
IStatus curr= status[i];
if (curr.matches(IStatus.ERROR)) {
return curr;
}
if (max == null || curr.getSeverity() > max.getSeverity()) {
max= curr;
}
}
return max;
}
/**
* Returns error-message / warning-message for a status.
* @return Array of size 2. Index 0 is the error message or <null>
* if not an error. Index 1 the warning message or <null> if not a warning.
*/
private static String[] getErrorMessages(IStatus status) {
String message= status.getMessage();
if (status.matches(IStatus.ERROR) && !"".equals(message)) { //$NON-NLS-1$
return new String[] { message, null };
} else if (status.matches(IStatus.WARNING | IStatus.INFO)) {
return new String[] { null, message };
} else {
return new String[] { null, null };
}
}
/**
* Applies the status to the status line of a dialog page.
*/
public static void applyToStatusLine(DialogPage page, IStatus status) {
String[] messages= getErrorMessages(status);
page.setErrorMessage(messages[0]);
page.setMessage(messages[1]);
}
/**
* Applies the status to a message line
*/
public static void applyToStatusLine(MessageLine messageLine, IStatus status) {
String[] messages= getErrorMessages(status);
messageLine.setErrorMessage(messages[0]);
messageLine.setMessage(messages[1]);
}
}
\ No newline at end of file diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/xmlcompare.properties b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/xmlcompare.properties deleted file mode 100644 index aaa375e9d..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/xmlcompare.properties +++ /dev/null @@ -1,109 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2003 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### - -# -# Structure Creator -# -XMLStructureCreator.pluginname= XML Compare -XMLStructureCreator.unordered= Unordered -XMLStructureCreator.ordered= Ordered -XMLStructureCreator.idmap_unordered= Unordered -XMLStructureCreator.id_map_scheme= Id Map Scheme: -XMLStructureCreator.body= body - - -# -# Id Scheme Drop Down Menu -# -ChooseMatcherDropDownAction.text= Compare Mode -ChooseMatcherDropDownAction.tooltip= Compare Mode - -# -# Preference Page -# -XMLComparePreference.idtype.attribute= attribute -XMLComparePreference.idtype.child_body= child text -XMLComparePreference.topTableLabel= Id Mapping schemes: -XMLComparePreference.topTableColumn1= Name -XMLComparePreference.topTableColumn2= Internal/User -XMLComparePreference.topTableColumn2internal= Internal -XMLComparePreference.topTableColumn2user= User -XMLComparePreference.topTableColumn3= Extension -XMLComparePreference.topAdd= &Add... -XMLComparePreference.topRename= &Edit... -XMLComparePreference.topRemove= &Remove -XMLComparePreference.topEdit= Edit &Copy... -XMLComparePreference.middleTableColumn1= Element -XMLComparePreference.middleTableColumn2= Path -XMLComparePreference.middleTableColumn3= Id Attribute -XMLComparePreference.middleTableColumn4= Id Source -XMLComparePreference.middleNew= &New... -XMLComparePreference.middleEdit= E&dit... -XMLComparePreference.middleRemove= Re&move -XMLComparePreference.middleTableLabel=Element mappings of selected Id Mapping Scheme: -XMLComparePreference.bottomTableLabel=Elements whose children are compared in ordered fashion: -XMLComparePreference.bottomTableColumn1=Element -XMLComparePreference.bottomTableColumn2=Path -XMLComparePreference.bottomNew=Ne&w... -XMLComparePreference.bottomEdit=Edi&t... -XMLComparePreference.bottomRemove=Remo&ve - -# -# Dialogs -# -XMLCompareAddIdMapDialog.editTitle= Edit Id Mapping Scheme -XMLCompareAddIdMapDialog.newTitle= New Id Mapping Scheme -XMLCompareAddIdMapDialog.label= ID Map Name: -XMLCompareAddIdMapDialog.extlabel= Extension (optional) -XMLCompareAddIdMapDialog.error.noname= Enter Id Map Name. -XMLCompareAddIdMapDialog.error.invalidname= Invalid Id Map Name. -XMLCompareAddIdMapDialog.error.idmapExists= Id Map already exists. -XMLCompareAddIdMapDialog.error.extfullstop= Extension cannot contain '.' -XMLCompareAddIdMapDialog.error.extExists= Extension already set for - -XMLCompareEditCopyIdMapDialog.title= Create Editable Copy of Internal Scheme -XMLCompareEditCopyIdMapDialog.comment= You cannon edit an internal Id Map Scheme.\nTherefore, a user copy of the Id Map Scheme will created for editing.\nThe extension associated with the internal Id Map Scheme will not be transferred.\n\nPlease Enter a new name for the Id Map Scheme copy. -XMLCompareEditCopyIdMapDialog.label= ID Map Name of Copy: -XMLCompareEditCopyIdMapDialog.error.noname= Enter Id Map Name. -XMLCompareEditCopyIdMapDialog.error.invalidname= Invalid Id Map Name. -XMLCompareEditCopyIdMapDialog.error.nameExists= Id Map Name already exists. - -XMLCompareEditMappingDialog.editTitle= Edit Mapping -XMLCompareEditMappingDialog.newTitle= New Mapping -XMLCompareEditMappingDialog.element= Element -XMLCompareEditMappingDialog.signature= Path -XMLCompareEditMappingDialog.idattribute= ID -XMLCompareEditMappingDialog.idtype= ID Source -XMLCompareEditMappingDialog.idtype.tooltip= Select whether the ID is an attribute of the element or the text of a child -XMLCompareEditMappingDialog.idtype.attribute.tooltip= ID is an attribute of the element -XMLCompareEditMappingDialog.idtype.childbody.tooltip= ID is the text of a child element -XMLCompareEditMappingDialog.error.noname= Enter Element Name. -XMLCompareEditMappingDialog.error.invalidname= Invalid Element Name. -XMLCompareEditMappingDialog.error.mappingExists= Mapping already exists. -XMLCompareEditMappingDialog.error.invalidsignature= Invalid Signature. -XMLCompareEditMappingDialog.error.invalididattribute= Invalid ID Attribute. - -XMLCompareEditOrderedDialog.newTitle=New Ordered -XMLCompareEditOrderedDialog.editTitle=Edit Ordered -XMLCompareEditOrderedDialog.error.orderedExists=Ordered entry already exists - -# -# XMLStructureViewer -# -XMLStructureViewer.newtask= Create new Id Map Scheme -XMLStructureViewer.action.notUserIdMap= Please select a User Id Mapping Scheme -XMLStructureViewer.action.setId.text1= Already set as Id -XMLStructureViewer.action.setId.text2= Replace existing Id -XMLStructureViewer.action.setId.text3= Set as Id -XMLStructureViewer.action.setOrdered.exists= Ordered entry exists already -XMLStructureViewer.action.setOrdered=Set children as ordered -XMLStructureViewer.matching.beginTask=Running Matching algorithm... - |