Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml')
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AbstractMatching.java314
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AttributesImpl.java331
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ChooseMatcherDropDownAction.java99
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/CreateNewIdMapAction.java63
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/IdMap.java142
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Mapping.java91
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Messages.java33
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/OrderedMatching.java217
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java149
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SelectMatcherAction.java31
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLChildren.java29
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareAddIdMapDialog.java141
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditCopyIdMapDialog.java116
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditMappingDialog.java215
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareEditOrderedDialog.java149
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareMessages.java101
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLComparePreferencePage.java839
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLNode.java170
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLPlugin.java398
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java807
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java562
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewerCreator.java31
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/MessageLine.java142
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusDialog.java164
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusInfo.java171
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusUtil.java85
-rw-r--r--examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/xmlcompare.properties109
27 files changed, 0 insertions, 5699 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 158b62412..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/AbstractMatching.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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= 0;
- while ((i<fNLeft.size()) && (fNLeft.elementAt(i) != x))
- i++;
- return i;
- }
-
- /* returns index of node y in fNRight */
- protected int indexOfRN (XMLNode y) {
- int j= 0;
- while ((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
- // TODO The dist method is order dependent but should not be
- int distance= dist(thisNode, otherNode);
- 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);
-
- 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;
- } 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;
- } else {
- ret= 1;
- fDT[index_x][index_y] = 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;
- }
- //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 0e4b257ea..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import 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 cd2f2d686..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ChooseMatcherDropDownAction.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.*;
-
-import org.eclipse.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.ChooseMatcherDropDownAction_text);
- setImageDescriptor(XMLPlugin.getDefault().getImageDescriptor("obj16/smartmode_co.gif")); //$NON-NLS-1$
- setToolTipText(XMLCompareMessages.ChooseMatcherDropDownAction_tooltip);
- setMenuCreator(this);
- }
-
- public void dispose() {
- // nothing to do
- }
-
- 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 f7741b17e..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.*;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.window.Window;
-
-/**
- * Button to create a new id mapping scheme
- */
-public class CreateNewIdMapAction extends Action {
-
- private HashMap fIdMaps;// HashMap ( idname -> HashMap (signature -> id) )
- private HashMap fIdMapsInternal;
- private HashMap fIdExtensionToName;
-
- public CreateNewIdMapAction(XMLStructureViewer viewer) {
- setImageDescriptor(XMLPlugin.getDefault().getImageDescriptor("obj16/addidmap.gif")); //$NON-NLS-1$
- setToolTipText(XMLCompareMessages.XMLStructureViewer_newtask);
- }
-
- 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/IdMap.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/IdMap.java
deleted file mode 100644
index 96c4f721e..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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 4bf6f5b8d..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-/**
- * 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;
- 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/Messages.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Messages.java
deleted file mode 100644
index 1a327aa38..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/Messages.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.text.MessageFormat;
-
-/**
- * Helper class to format message strings.
- *
- * @since 3.1
- */
-public class Messages {
-
- public static String format(String message, Object object) {
- return MessageFormat.format(message, new Object[] { object});
- }
-
- public static String format(String message, Object[] objects) {
- return MessageFormat.format(message, objects);
- }
-
- private Messages() {
- // Not for instantiation
- }
-}
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 325a6ce72..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/OrderedMatching.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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) {
-
- 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 67daa33b5..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-
-import 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);
- }
- }
-}
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 a58623343..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import 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 300255b47..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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 7e0eb9615..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.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.XMLCompareAddIdMapDialog_editTitle);
- else
- setTitle(XMLCompareMessages.XMLCompareAddIdMapDialog_newTitle);
-
- 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 ancestor 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.XMLCompareAddIdMapDialog_label);
- 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.XMLCompareAddIdMapDialog_extlabel);
- 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.XMLCompareAddIdMapDialog_error_noname);
- else if (XMLComparePreferencePage.containsInvalidCharacters(newText))
- status.setError(XMLCompareMessages.XMLCompareAddIdMapDialog_error_invalidname);
- else if ( (!fEdit && (fIdMaps.containsKey(newText) || fIdMapsInternal.containsKey(newText)) )
- || (fEdit && !newText.equals(fIdMap.getName()) && (fIdMaps.containsKey(newText) || fIdMapsInternal.containsKey(newText)) )
- )
- status.setError(XMLCompareMessages.XMLCompareAddIdMapDialog_error_idmapExists);
- newText= fIdMapExtText.getText().toLowerCase();
- if (newText.length() > 0) {
- if (newText.indexOf(".") > -1) //$NON-NLS-1$
- status.setError(XMLCompareMessages.XMLCompareAddIdMapDialog_error_extfullstop);
- else if (fIdExtensionToName.containsKey(newText) && !fIdExtensionToName.get(newText).equals(fIdMap.getName()))
- status.setError(MessageFormat.format("{0} {1}",new String[] {XMLCompareMessages.XMLCompareAddIdMapDialog_error_extExists,(String)fIdExtensionToName.get(newText)})); //$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 cd0881ba3..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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.XMLCompareEditCopyIdMapDialog_title);
-
- 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 ancestor 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.XMLCompareEditCopyIdMapDialog_comment);
- 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.XMLCompareEditCopyIdMapDialog_label);
- 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.XMLCompareEditCopyIdMapDialog_error_noname);
- else if (XMLComparePreferencePage.containsInvalidCharacters(newText))
- status.setError(XMLCompareMessages.XMLCompareEditCopyIdMapDialog_error_invalidname);
- else if (fIdMaps.containsKey(newText) || fIdMapsInternal.containsKey(newText))
- status.setError(XMLCompareMessages.XMLCompareEditCopyIdMapDialog_error_nameExists);
- updateStatus(status);
- }
-
- /**
- * Notifies that the ok button of this dialog has been pressed.
- */
- protected void okPressed() {
- fResult= fIdMapText.getText();
- super.okPressed();
- }
-}
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 7b3d24c2e..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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.XMLCompareEditMappingDialog_editTitle);
- else
- setTitle(XMLCompareMessages.XMLCompareEditMappingDialog_newTitle);
-
- fMapping= mapping;
- fIdmapHM= idmapHM;
- }
-
- /**
- * Creates and returns the contents of the upper part
- * of the dialog (above the button bar).
- *
- * Subclasses should override.
- *
- * @param ancestor 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.XMLCompareEditMappingDialog_element);
- 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.XMLCompareEditMappingDialog_signature);
- 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.XMLCompareEditMappingDialog_idattribute);
- 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.XMLCompareEditMappingDialog_error_noname;
- isError= true;
- } else if (XMLComparePreferencePage.containsInvalidCharacters(text)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditMappingDialog_error_invalidname; //$NON-NLS-1$
- isError= true;
- } else if (!fEdit && fIdmapHM != null && fIdmapHM.containsKey(mappingKey)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditMappingDialog_error_mappingExists; //$NON-NLS-1$
- isError= true;
- }
- text= fSignatureText.getText();
- if (XMLComparePreferencePage.containsInvalidCharacters(text)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditMappingDialog_error_invalidsignature; //$NON-NLS-1$
- isError= true;
- }
- text= fIdAttributeText.getText();
- if (text.length() == 0)
- isError= true;
- else if (XMLComparePreferencePage.containsInvalidCharacters(text)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditMappingDialog_error_invalididattribute; //$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.XMLCompareEditMappingDialog_idtype);
- titleLabel.setToolTipText(XMLCompareMessages.XMLCompareEditMappingDialog_idtype_tooltip);
-
- 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.XMLComparePreference_idtype_attribute);
- fIdTypeAttributeButton.setToolTipText(XMLCompareMessages.XMLCompareEditMappingDialog_idtype_attribute_tooltip);
-
- //child body button
- fIdTypeChildBodyButton= createRadioButton(buttonComposite, XMLCompareMessages.XMLComparePreference_idtype_child_body);
- fIdTypeChildBodyButton.setToolTipText(XMLCompareMessages.XMLCompareEditMappingDialog_idtype_childbody_tooltip);
-
- 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;
- }
-}
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 c519224d6..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.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.XMLCompareEditOrderedDialog_editTitle);
- else
- setTitle(XMLCompareMessages.XMLCompareEditOrderedDialog_newTitle);
-
- fMapping= mapping;
- fIdmapAL= idmapAL;
- }
-
- /**
- * Creates and returns the contents of the upper part
- * of the dialog (above the button bar).
- *
- * Subclasses should override.
- *
- * @param ancestor 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.XMLCompareEditMappingDialog_element);
- 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.XMLCompareEditMappingDialog_signature);
- 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.XMLCompareEditMappingDialog_error_noname;
- isError= true;
- } else if (XMLComparePreferencePage.containsInvalidCharacters(text)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditMappingDialog_error_invalidname; //$NON-NLS-1$
- isError= true;
- } else if (!fEdit && fIdmapAL.contains(mappingKey)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditOrderedDialog_error_orderedExists; //$NON-NLS-1$
- isError= true;
- }
- text= fSignatureText.getText();
- if (XMLComparePreferencePage.containsInvalidCharacters(text)) {
- if (errormsg == "") errormsg= XMLCompareMessages.XMLCompareEditMappingDialog_error_invalidsignature; //$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();
- }
-}
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 aefee5437..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLCompareMessages.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import org.eclipse.osgi.util.NLS;
-
-public final class XMLCompareMessages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.compare.examples.xml.xmlcompare";//$NON-NLS-1$
-
- private XMLCompareMessages() {
- // Do not instantiate
- }
-
- public static String XMLStructureCreator_pluginname;
- public static String XMLStructureCreator_unordered;
- public static String XMLStructureCreator_ordered;
- public static String XMLStructureCreator_idmap_unordered;
- public static String XMLStructureCreator_id_map_scheme;
- public static String XMLStructureCreator_body;
- public static String ChooseMatcherDropDownAction_text;
- public static String ChooseMatcherDropDownAction_tooltip;
- public static String XMLComparePreference_idtype_attribute;
- public static String XMLComparePreference_idtype_child_body;
- public static String XMLComparePreference_topTableLabel;
- public static String XMLComparePreference_topTableColumn1;
- public static String XMLComparePreference_topTableColumn2;
- public static String XMLComparePreference_topTableColumn2internal;
- public static String XMLComparePreference_topTableColumn2user;
- public static String XMLComparePreference_topTableColumn3;
- public static String XMLComparePreference_topAdd;
- public static String XMLComparePreference_topRename;
- public static String XMLComparePreference_topRemove;
- public static String XMLComparePreference_topEdit;
- public static String XMLComparePreference_middleTableColumn1;
- public static String XMLComparePreference_middleTableColumn2;
- public static String XMLComparePreference_middleTableColumn3;
- public static String XMLComparePreference_middleTableColumn4;
- public static String XMLComparePreference_middleNew;
- public static String XMLComparePreference_middleEdit;
- public static String XMLComparePreference_middleRemove;
- public static String XMLComparePreference_middleTableLabel;
- public static String XMLComparePreference_bottomTableLabel;
- public static String XMLComparePreference_bottomTableColumn1;
- public static String XMLComparePreference_bottomTableColumn2;
- public static String XMLComparePreference_bottomNew;
- public static String XMLComparePreference_bottomEdit;
- public static String XMLComparePreference_bottomRemove;
- public static String XMLCompareAddIdMapDialog_editTitle;
- public static String XMLCompareAddIdMapDialog_newTitle;
- public static String XMLCompareAddIdMapDialog_label;
- public static String XMLCompareAddIdMapDialog_extlabel;
- public static String XMLCompareAddIdMapDialog_error_noname;
- public static String XMLCompareAddIdMapDialog_error_invalidname;
- public static String XMLCompareAddIdMapDialog_error_idmapExists;
- public static String XMLCompareAddIdMapDialog_error_extfullstop;
- public static String XMLCompareAddIdMapDialog_error_extExists;
- public static String XMLCompareEditCopyIdMapDialog_title;
- public static String XMLCompareEditCopyIdMapDialog_comment;
- public static String XMLCompareEditCopyIdMapDialog_label;
- public static String XMLCompareEditCopyIdMapDialog_error_noname;
- public static String XMLCompareEditCopyIdMapDialog_error_invalidname;
- public static String XMLCompareEditCopyIdMapDialog_error_nameExists;
- public static String XMLCompareEditMappingDialog_editTitle;
- public static String XMLCompareEditMappingDialog_newTitle;
- public static String XMLCompareEditMappingDialog_element;
- public static String XMLCompareEditMappingDialog_signature;
- public static String XMLCompareEditMappingDialog_idattribute;
- public static String XMLCompareEditMappingDialog_idtype;
- public static String XMLCompareEditMappingDialog_idtype_tooltip;
- public static String XMLCompareEditMappingDialog_idtype_attribute_tooltip;
- public static String XMLCompareEditMappingDialog_idtype_childbody_tooltip;
- public static String XMLCompareEditMappingDialog_error_noname;
- public static String XMLCompareEditMappingDialog_error_invalidname;
- public static String XMLCompareEditMappingDialog_error_mappingExists;
- public static String XMLCompareEditMappingDialog_error_invalidsignature;
- public static String XMLCompareEditMappingDialog_error_invalididattribute;
- public static String XMLCompareEditOrderedDialog_newTitle;
- public static String XMLCompareEditOrderedDialog_editTitle;
- public static String XMLCompareEditOrderedDialog_error_orderedExists;
- public static String XMLStructureViewer_newtask;
- public static String XMLStructureViewer_action_notUserIdMap;
- public static String XMLStructureViewer_action_setId_text1;
- public static String XMLStructureViewer_action_setId_text2;
- public static String XMLStructureViewer_action_setId_text3;
- public static String XMLStructureViewer_action_setOrdered_exists;
- public static String XMLStructureViewer_action_setOrdered;
- public static String XMLStructureViewer_matching_beginTask;
-
- static {
- NLS.initializeMessages(BUNDLE_NAME, XMLCompareMessages.class);
- }
-} \ No newline at end of file
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 4319fa8ca..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLComparePreferencePage.java
+++ /dev/null
@@ -1,839 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.util.*;
-
-import org.eclipse.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.XMLComparePreference_idtype_attribute;
- public static String IDTYPE_CHILDBODY= XMLCompareMessages.XMLComparePreference_idtype_child_body;
-
-
- 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.XMLComparePreference_topTableLabel);
- 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.XMLComparePreference_topTableColumn2;
- String column3Text= XMLCompareMessages.XMLComparePreference_topTableColumn3;
- 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.XMLComparePreference_topTableColumn1);
- column = new TableColumn(fIdMapsTable, SWT.NONE);
- column.setText(column2Text);
- column = new TableColumn(fIdMapsTable, SWT.NONE);
- column.setText(column3Text);
-
- 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.XMLComparePreference_topAdd);
- 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.XMLComparePreference_topRename);
- 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.XMLComparePreference_topRemove);
- 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.XMLComparePreference_topEdit);
- 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.XMLComparePreference_middleTableLabel);
- 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.XMLComparePreference_middleTableColumn3;
- String column4Text= XMLCompareMessages.XMLComparePreference_middleTableColumn4;
- 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.XMLComparePreference_middleTableColumn1);
- column = new TableColumn(fMappingsTable, SWT.NONE);
- column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn2);
- column = new TableColumn(fMappingsTable, SWT.NONE);
- column.setText(column3Text);
- column = new TableColumn(fMappingsTable, SWT.NONE);
- column.setText(column4Text);
-
- 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.XMLComparePreference_middleNew);
- 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.XMLComparePreference_middleEdit);
- 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.XMLComparePreference_middleRemove);
- 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.XMLComparePreference_bottomTableLabel);
- 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.XMLComparePreference_bottomTableColumn1);
- column = new TableColumn(fOrderedTable, SWT.NONE);
- column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn2);
-
- 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.XMLComparePreference_bottomNew);
- 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.XMLComparePreference_bottomEdit);
- 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.XMLComparePreference_bottomRemove);
- 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) {
- // empty implementation
- }
-
- 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 enumeration= Mappings.elements(); enumeration.hasMoreElements(); ) {
- Mapping mapping = (Mapping) enumeration.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= 0;
- while (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.XMLComparePreference_topTableColumn2internal:XMLCompareMessages.XMLComparePreference_topTableColumn2user,idmap.getExtension()};
- 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= 0;
- while (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= 0;
- while (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 enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
- newMappingsTableItem((Mapping)enumeration.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 8adba4b36..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLNode.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import 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);
- 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 fa98c3df6..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLPlugin.java
+++ /dev/null
@@ -1,398 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.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.core.runtime.ListenerList;
-
-import org.eclipse.compare.CompareUI;
-import org.eclipse.core.runtime.*;
-import org.osgi.framework.BundleContext;
-
-/**
- * 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 {
-
- 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;
-
- private ListenerList fViewers= new ListenerList();
-
-
- /**
- * 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.
- */
- public XMLPlugin() {
- super();
- Assert.isTrue(fgXMLPlugin == null);
- fgXMLPlugin= this;
- }
-
- public void start(BundleContext context) throws Exception {
- super.start(context);
-
- 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();
-
- URL installURL= fgXMLPlugin.getBundle().getEntry("/"); //$NON-NLS-1$
- 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() {
- IExtensionRegistry registry= Platform.getExtensionRegistry();
-
- // 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;
- }
- 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().getBundle().getSymbolicName();
- }
-}
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 eda121f70..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java
+++ /dev/null
@@ -1,807 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-
-import java.text.MessageFormat;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-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;
-
-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.eclipse.compare.IEditableContent;
-import org.eclipse.compare.IEncodedStreamContentAccessor;
-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;
-
-/**
- * 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;
-
- public static final String DEFAULT_NAME= XMLCompareMessages.XMLStructureCreator_pluginname;
-
- public static final String USE_UNORDERED= XMLCompareMessages.XMLStructureCreator_unordered;
- public static final String USE_ORDERED= XMLCompareMessages.XMLStructureCreator_ordered;
- public static final String DEFAULT_IDMAP= USE_ORDERED;
-
- 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.XMLStructureCreator_idmap_unordered;
- public static final char ID_SEPARATOR= '<';
- public static final char ID_TYPE_BODY= '<';
-
- private XMLNode fcurrentParent;
- private String fsignature;
- private Document fdoc;
- private boolean ignoreBodies= false;
- private HashMap fIdMapsInternal;
- private HashMap fIdMaps;
- private HashMap fIdExtensionToName;
- private HashMap fOrderedElementsInternal;
- private HashMap fOrderedElements;
- private HashMap idMap;
- private ArrayList fOrdered;
- private String fIdMapToUse;
- private boolean fUseIdMap;
- 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);
- }
-
- /** Start document. */
- public void startDocument() {
- prevlocator= new LocatorImpl(locator);
- }
-
- /* 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-1$
- }
- int start= r.getOffset() + prevlocator.getColumnNumber() - 1;
- if (start < 0)
- start= 0;
- currentElement= new XMLChildren(TYPE_ELEMENT, elementId, elementId, (fsignature + SIGN_ELEMENT), fdoc, start, 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);
- }
-
- /* 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.XMLStructureCreator_body, Integer.toString(fcurrentParent.bodies)})); //$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);
- }
-
- /* Ignorable whitespace. */
- public void ignorableWhitespace(char ch[], int start, int length) {
- //
- //// characters(ch, start, length);
- //// System.out.flush();
- //
- prevlocator= new LocatorImpl(locator);
- }
-
- /* 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$
- }
-
- //
- // 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();
-
- }
- }
-
- 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;
- }
-
- /*
- * 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);
- 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(new StringReader(contents)), 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) {
- // nothing to do
- }
-
- public void save(IStructureComparator structure, Object input) {
- if (input instanceof IEditableContent && structure instanceof XMLNode) {
- IDocument document= ((XMLNode) structure).getDocument();
- IEditableContent bca= (IEditableContent) input;
- String contents= document.get();
- String encoding= null;
- if (input instanceof IEncodedStreamContentAccessor) {
- try {
- encoding= ((IEncodedStreamContentAccessor)input).getCharset();
- } catch (CoreException e1) {
- // ignore
- }
- }
- if (encoding == null)
- encoding= "UTF-8"; //$NON-NLS-1$
- try {
- bca.setContent(contents.getBytes(encoding));
- } catch (UnsupportedEncodingException e) {
- bca.setContent(contents.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;
- }
-
- static String readString(IStreamContentAccessor sa) throws CoreException {
- InputStream is= sa.getContents();
- String encoding= null;
- if (sa instanceof IEncodedStreamContentAccessor)
- encoding= ((IEncodedStreamContentAccessor) sa).getCharset();
- if (encoding == null)
- encoding= "UTF-8"; //$NON-NLS-1$
- return readString(is, encoding);
- }
-
- /*
- * Returns null if an error occurred.
- */
- private static String readString(InputStream is, String encoding) {
- 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, encoding));
-
- while ((read= reader.read(part)) != -1)
- buffer.append(part, 0, read);
-
- return buffer.toString();
-
- } catch (IOException ex) {
- // NeedWork
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException ex) {
- // silently ignored
- }
- }
- }
- return null;
- }
-
- /* Returns a sorted list of attributes.
- */
- 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;
-
- }
-
- 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 42eb3f967..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java
+++ /dev/null
@@ -1,562 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import java.text.MessageFormat;
-import java.util.*;
-
-import org.eclipse.compare.*;
-import org.eclipse.compare.structuremergeviewer.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jface.action.*;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.viewers.*;
-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 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;
-
- 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;
- return 1;
- }
- }
-
- /**
- * 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
- */
- 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());
-
- }
-
- protected void preDiffHook(
- IStructureComparator ancestor,
- IStructureComparator left,
- IStructureComparator right, IProgressMonitor monitor) {
- // if (!xsc.getIdMap().equals(XMLStructureCreator.USE_ORDERED)) {
- //TimeoutContext.run(true, TIMEOUT, getControl().getShell(), runnable);
- if (left != null && right != null) {
- performMatching((XMLNode)left, (XMLNode)right, (XMLNode)ancestor, monitor);
- }
- }
-
- /**
- * 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.XMLStructureViewer_action_notUserIdMap);
- 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.XMLStructureViewer_action_setId_text1);
- 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.XMLStructureViewer_action_setId_text2, oldId })); //$NON-NLS-1$
- action.setEnabled(true);
- }
- } else {
- action.setText(XMLCompareMessages.XMLStructureViewer_action_setId_text3);
- 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.XMLStructureViewer_action_notUserIdMap);
- 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.XMLStructureViewer_action_setOrdered_exists);
- action.setEnabled(false);
- } else {
- action.setText(XMLCompareMessages.XMLStructureViewer_action_setOrdered);
- 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();
- }
- }
-
- private void performMatching(final XMLNode left, final XMLNode right,
- final XMLNode ancestor, IProgressMonitor monitor) {
- if (monitor == null) {
- monitor= new NullProgressMonitor();
- }
- int totalWork;
- if (ancestor != null)
- totalWork= 1;
- else
- totalWork= 3;
- monitor.beginTask(XMLCompareMessages.XMLStructureViewer_matching_beginTask, totalWork);
- 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= null;
- if (getXMLStructureCreator()
- .getIdMap()
- .equals(XMLStructureCreator.USE_ORDERED)) {
- m= new OrderedMatching();
- if (getSorter() instanceof XMLSorter)
- ((XMLSorter) getSorter()).setAlwaysOrderSort(true);
- }
- try {
- if (m != null) {
- 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();
- }
- }
-}
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 cd13d4792..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml;
-
-import 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 506501781..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml.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);
- }
- }
-
-}
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 455dad1e6..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml.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) {
- // empty default implementation
- }
-
- /*
- * 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);
- }
- }
-
- /*
- * 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);
- }
-
-}
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 c5835e928..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, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml.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];
- }
-
-}
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 47c7c03a0..000000000
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/StatusUtil.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.xml.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;
- 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]);
- }
-}
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 8f8ff321f..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, 2005 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-#
-# 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...
-

Back to the top