Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples/org.eclipse.compare.examples/src/org/eclipse/compare')
-rw-r--r--examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/CompareExampleMessages.properties16
-rw-r--r--examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/KeyValuePairStructureCreator.java156
-rw-r--r--examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/TextMergeViewerCreator.java31
-rw-r--r--examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/Util.java80
4 files changed, 0 insertions, 283 deletions
diff --git a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/CompareExampleMessages.properties b/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/CompareExampleMessages.properties
deleted file mode 100644
index d59e04685..000000000
--- a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/CompareExampleMessages.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-#
-# Resource strings
-#
-KeyValuePairStructureCreator.title= Key/Value Pair Compare
-KeyValuePairStructureCreator.CoreException.message= CoreException
-KeyValuePairStructureCreator.BadLocationException.message= BadLocationException
diff --git a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/KeyValuePairStructureCreator.java b/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/KeyValuePairStructureCreator.java
deleted file mode 100644
index 675c1a5af..000000000
--- a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/KeyValuePairStructureCreator.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.structurecreator;
-
-import org.eclipse.swt.graphics.*;
-
-import org.eclipse.jface.text.*;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-import org.eclipse.compare.*;
-import org.eclipse.compare.structuremergeviewer.*;
-
-
-/**
- * This structure creator parses input containing key/value pairs
- * and returns the pairs as a tree of <code>IStructureComparator</code>s.
- * Each key/value pair must be on a separate line and keys are separated
- * from values by a '='.
- * <p>
- * Example:
- * <pre>
- * foo=bar
- * name=joe
- * </pre>
- */
-public class KeyValuePairStructureCreator implements IStructureCreator {
-
- static class KeyValueNode extends DocumentRangeNode implements ITypedElement {
-
- String fValue;
-
- public KeyValueNode(String id, String value, IDocument doc, int start, int length) {
- super(0, id, doc, start, length);
- fValue= value;
- }
-
- String getValue() {
- return fValue;
- }
-
- /*
- * @see ITypedElement#getName
- */
- public String getName() {
- return this.getId();
- }
-
- /*
- * Every key/value pair is of type "kvtxt". We register a TextMergeViewer for it.
- * @see ITypedElement#getType
- */
- public String getType() {
- return "kvtxt"; //$NON-NLS-1$
- }
-
- /*
- * @see ITypedElement#getImage
- */
- public Image getImage() {
- return CompareUI.getImage(getType());
- }
- }
-
-
- public KeyValuePairStructureCreator() {
- // nothing to do
- }
-
- /*
- * This title will be shown in the title bar of the structure compare pane.
- */
- public String getName() {
- return Util.getString("KeyValuePairStructureCreator.title"); //$NON-NLS-1$
- }
-
- /*
- * Returns a node.
- */
- public IStructureComparator getStructure(Object input) {
-
- if (!(input instanceof IStreamContentAccessor))
- return null;
-
- IStreamContentAccessor sca= (IStreamContentAccessor) input;
- try {
- String contents= Util.readString(sca);
- if (contents == null)
- contents= ""; //$NON-NLS-1$
- Document doc= new Document(contents);
-
- KeyValueNode root= new KeyValueNode("root", "", doc, 0, doc.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
-
- for (int i= 0; i < doc.getNumberOfLines(); i++) {
-
- IRegion r= doc.getLineInformation(i);
- String s= doc.get(r.getOffset(), r.getLength());
- int start= r.getOffset();
-
- String key= ""; //$NON-NLS-1$
- String value= ""; //$NON-NLS-1$
- int pos= s.indexOf('=');
- if (pos >= 0) {
- key= s.substring(0, pos);
- value= s.substring(pos+1);
- } else {
- key= s;
- }
- if (key.length() > 0)
- root.addChild(new KeyValueNode(key, value, doc, start, s.length()));
- }
- return root;
- } catch (CoreException ex) {
- String message= Util.getString("KeyValuePairStructureCreator.CoreException.message"); //$NON-NLS-1$
- CompareUI.getPlugin().getLog().log(new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, 0, message, ex));
- } catch (BadLocationException ex) {
- String message= Util.getString("KeyValuePairStructureCreator.BadLocationException.message"); //$NON-NLS-1$
- CompareUI.getPlugin().getLog().log(new Status(IStatus.ERROR, CompareUI.PLUGIN_ID, 0, message, ex));
- }
-
- return null;
- }
-
- public void save(IStructureComparator structure, Object input) {
- if (input instanceof IEditableContent && structure instanceof KeyValueNode) {
- IDocument doc= ((KeyValueNode)structure).getDocument();
- IEditableContent bca= (IEditableContent) input;
- String c= doc.get();
- bca.setContent(c.getBytes());
- }
- }
-
- public String getContents(Object node, boolean ignoreWhitespace) {
- if (node instanceof KeyValueNode) {
- String s= ((KeyValueNode)node).getValue();
- if (ignoreWhitespace)
- s= s.trim();
- return s;
- }
- return null;
- }
-
- public IStructureComparator locate(Object path, Object source) {
- return null;
- }
-}
diff --git a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/TextMergeViewerCreator.java b/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/TextMergeViewerCreator.java
deleted file mode 100644
index 3448ff02a..000000000
--- a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/TextMergeViewerCreator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.structurecreator;
-
-import org.eclipse.swt.widgets.Composite;
-
-import org.eclipse.jface.viewers.Viewer;
-
-import org.eclipse.compare.*;
-import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
-
-/**
- * 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 TextMergeViewerCreator implements IViewerCreator {
-
- public Viewer createViewer(Composite parent, CompareConfiguration mp) {
- return new TextMergeViewer(parent, mp);
- }
-}
diff --git a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/Util.java b/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/Util.java
deleted file mode 100644
index d048ac803..000000000
--- a/examples/org.eclipse.compare.examples/src/org/eclipse/compare/examples/structurecreator/Util.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.compare.examples.structurecreator;
-
-import java.io.*;
-import java.util.*;
-
-import org.eclipse.compare.IStreamContentAccessor;
-import org.eclipse.compare.IEncodedStreamContentAccessor;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-
-
-public class Util {
-
- private static final String RESOURCE_BUNDLE= "org.eclipse.compare.examples.structurecreator.CompareExampleMessages"; //$NON-NLS-1$
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
- }
- }
-
- /*
- * Reads the contents of the given input stream into a string.
- * The function assumes that the input stream uses the platform's default encoding
- * (<code>ResourcesPlugin.getEncoding()</code>).
- * 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) {
- // silently ignored
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException ex) {
- // we don't log IOException when closing a file
- }
- }
- }
- 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= ResourcesPlugin.getEncoding();
- return readString(is, encoding);
- }
-}

Back to the top