From 2a9aeb60ad86b2cbad22eac537432bc770a63a94 Mon Sep 17 00:00:00 2001
From: axelcl
+ * Mementos were designed with the following requirements in mind:
+ * net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY
+ *
+ */
+ public Configuration() {
+ this(PHPHelpPlugin.HTTP_QUERY); // default type
+ }
+
+ /**
+ * Construct a Configuration with a type
+ * @param type Example: net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY
+ *
+ * @see net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin
+ */
+ public Configuration(String type) {
+ this.fType = type;
+ }
+
+ public String getId() {
+ return fId;
+ }
+
+ public String getName() {
+ return fName;
+ }
+
+ public String getURL() {
+ return fUrl;
+ }
+
+ public String getPassword() {
+ return fPassword;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.monitor.internal.IConfiguration#getLocalPort()
+ */
+ public String getUser() {
+ return fUser;
+ }
+
+ /**
+ */
+ public String getType() {
+ return fType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.monitor.internal.IConfiguration#isRunning()
+ */
+ public boolean isActive() {
+ return ConfigurationManager.getInstance().isActive(this);
+ }
+
+ public void delete() {
+ ConfigurationManager.getInstance().removeConfiguration(this);
+ }
+
+ public boolean isWorkingCopy() {
+ return false;
+ }
+
+ public IConfigurationWorkingCopy getWorkingCopy() {
+ return new ConfigurationWorkingCopy(this);
+ }
+
+ protected void setInternal(IConfiguration monitor) {
+ fId = monitor.getId();
+ fName = monitor.getName();
+ fUrl = monitor.getURL();
+ fPassword = monitor.getPassword();
+ fUser = monitor.getUser();
+ fType = monitor.getType();
+ }
+
+ protected void save(IMemento memento) {
+ memento.putString(MEMENTO_ID, fId);
+ memento.putString(MEMENTO_NAME, fName);
+ memento.putString(MEMENTO_TYPE_ID, fType);
+ memento.putString(MEMENTO_USER, fUser);
+ memento.putString(MEMENTO_URL, fUrl);
+ String result = 'A' + scramblePassword(fPassword);
+ memento.putString(MEMENTO_PASSWORD, result);
+ }
+
+ protected void load(IMemento memento) {
+ fId = memento.getString(MEMENTO_ID);
+ if (fId == null) {
+ fId = "";
+ }
+ fName = memento.getString(MEMENTO_NAME);
+ if (fName == null) {
+ fName = "";
+ }
+ fType = memento.getString(MEMENTO_TYPE_ID);
+ if (fType == null) {
+ fType = "";
+ }
+ fUser = memento.getString(MEMENTO_USER);
+ if (fUser == null) {
+ fUser = "";
+ }
+ fUrl = memento.getString(MEMENTO_URL);
+ if (fUrl == null) {
+ fUrl = "";
+ }
+ String result = memento.getString(MEMENTO_PASSWORD);
+
+ if (result == null) {
+ fPassword = "";
+ } else {
+ fPassword = scramblePassword(result.substring(1));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(fName);
+ buffer.append(" - ");
+ buffer.append(fUser);
+ buffer.append(" - ");
+ buffer.append(fUrl);
+ buffer.append(" - ");
+ buffer.append(fType);
+ return buffer.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ if (o instanceof IConfiguration) {
+ return fName.compareTo(((IConfiguration) o).getName());
+ }
+ return 1;
+ }
+
+ private static String scramblePassword(String password) {
+ int length = password.length();
+ char[] out = new char[length];
+ for (int i = 0; i < length; i++) {
+ char value = password.charAt(i);
+ out[i] = SCRAMBLING_TABLE[value];
+ }
+ return new String(out);
+ }
+
+ public boolean isUserComplete() {
+ if (fUser == null || fUser.equals("")) {
+ return false;
+ }
+ if (fPassword == null || fPassword.equals("")) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof Configuration) {
+ if (fName == null || ((Configuration) obj).fName == null) {
+ return false;
+ }
+ return fName.equals(((Configuration) obj).fName);
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationManager.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationManager.java
new file mode 100644
index 0000000..2b23dea
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationManager.java
@@ -0,0 +1,184 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+�*
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+import org.eclipse.core.runtime.Preferences;
+/**
+ *
+ */
+public class ConfigurationManager {
+ private static final int ADD = 0;
+ private static final int CHANGE = 1;
+ private static final int REMOVE = 2;
+
+ // configurations
+ protected List configurations;
+ protected Map threads = new HashMap();
+
+ protected List configurationListeners = new ArrayList();
+
+ private Preferences.IPropertyChangeListener pcl;
+ protected boolean ignorePreferenceChanges = false;
+
+ protected static ConfigurationManager instance;
+
+ public static ConfigurationManager getInstance() {
+ if (instance == null)
+ instance = new ConfigurationManager();
+ return instance;
+ }
+
+ private ConfigurationManager() {
+ loadConfigurations();
+
+ pcl = new Preferences.IPropertyChangeListener() {
+ public void propertyChange(Preferences.PropertyChangeEvent event) {
+ if (ignorePreferenceChanges)
+ return;
+ String property = event.getProperty();
+ if (property.equals(PHPHelpPlugin.PREF_STRING_CONFIGURATIONS)) {
+ loadConfigurations();
+ }
+ }
+ };
+
+ PHPHelpPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(pcl);
+ }
+
+ protected void dispose() {
+ PHPHelpPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(pcl);
+ }
+
+ public IConfigurationWorkingCopy createConfiguration() {
+ return new ConfigurationWorkingCopy();
+ }
+
+ public List getConfigurations() {
+ return new ArrayList(configurations);
+ }
+
+ protected void addConfiguration(IConfiguration configuration) {
+ if (!configurations.contains(configuration))
+ configurations.add(configuration);
+ fireConfigurationEvent(configuration, ADD);
+ saveConfigurations();
+ }
+
+ protected boolean isActive(IConfiguration configuration) {
+ return (threads.get(configuration) != null);
+ }
+
+ protected void removeConfiguration(IConfiguration configuration) {
+ configurations.remove(configuration);
+ fireConfigurationEvent(configuration, REMOVE);
+ saveConfigurations();
+ }
+
+ protected void configurationChanged(IConfiguration configuration) {
+ fireConfigurationEvent(configuration, CHANGE);
+ saveConfigurations();
+ }
+
+ /**
+ * Add monitor listener.
+ *
+ * @param listener
+ */
+ public void addConfigurationListener(IConfigurationListener listener) {
+ configurationListeners.add(listener);
+ }
+
+ /**
+ * Remove monitor listener.
+ *
+ * @param listener
+ */
+ public void removeConfigurationListener(IConfigurationListener listener) {
+ configurationListeners.remove(listener);
+ }
+
+ /**
+ * Fire a monitor event.
+ * @param rr
+ * @param fType
+ */
+ protected void fireConfigurationEvent(IConfiguration configuration, int type) {
+ Object[] obj = configurationListeners.toArray();
+
+ int size = obj.length;
+ for (int i = 0; i < size; i++) {
+ IConfigurationListener listener = (IConfigurationListener) obj[i];
+ if (type == ADD)
+ listener.configurationAdded(configuration);
+ else if (type == CHANGE)
+ listener.configurationChanged(configuration);
+ else if (type == REMOVE)
+ listener.configurationRemoved(configuration);
+ }
+ }
+
+
+
+
+ protected void loadConfigurations() {
+
+ configurations = new ArrayList();
+ Preferences prefs = PHPHelpPlugin.getDefault().getPluginPreferences();
+ String xmlString = prefs.getString(PHPHelpPlugin.PREF_STRING_CONFIGURATIONS);
+ if (xmlString != null && xmlString.length() > 0) {
+ try {
+ ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes());
+ IMemento memento = XMLMemento.loadMemento(in);
+
+ IMemento[] children = memento.getChildren("config");
+ if (children != null) {
+ int size = children.length;
+ for (int i = 0; i < size; i++) {
+ Configuration configuration = new ConfigurationWorkingCopy();
+ configuration.load(children[i]);
+ configurations.add(configuration);
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ protected void saveConfigurations() {
+ try {
+ ignorePreferenceChanges = true;
+ XMLMemento memento = XMLMemento.createWriteRoot(PHPHelpPlugin.PREF_STRING_CONFIGURATIONS);
+
+ Iterator iterator = configurations.iterator();
+ while (iterator.hasNext()) {
+ Configuration monitor = (Configuration) iterator.next();
+ IMemento child = memento.createChild("config");
+ monitor.save(child);
+ }
+
+ String xmlString = memento.saveToString();
+ Preferences prefs = PHPHelpPlugin.getDefault().getPluginPreferences();
+ prefs.setValue(PHPHelpPlugin.PREF_STRING_CONFIGURATIONS, xmlString);
+ PHPHelpPlugin.getDefault().savePluginPreferences();
+ } catch (Exception e) {
+ }
+ ignorePreferenceChanges = false;
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationWorkingCopy.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationWorkingCopy.java
new file mode 100644
index 0000000..97742a3
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationWorkingCopy.java
@@ -0,0 +1,76 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+
+/**
+ *
+ */
+public class ConfigurationWorkingCopy extends Configuration implements IConfigurationWorkingCopy {
+ protected Configuration configuration;
+
+ // creation
+ public ConfigurationWorkingCopy() { }
+
+ // working copy
+ public ConfigurationWorkingCopy(Configuration configuration) {
+ this.configuration = configuration;
+ setInternal(configuration);
+ }
+
+ public void setId(String newId) {
+ fId = newId;
+ }
+
+ public void setName(String name) {
+ fName = name;
+ }
+
+
+ public void setURL(String url) {
+ fUrl = url;
+ }
+
+
+ public void setPassword(String password) {
+ fPassword = password;
+ }
+
+
+ public void setUser(String user) {
+ fUser = user;
+ }
+
+
+ public void setType(String t) {
+ fType = t;
+ }
+
+ public boolean isWorkingCopy() {
+ return true;
+ }
+
+ public IConfigurationWorkingCopy getWorkingCopy() {
+ return this;
+ }
+
+ public IConfiguration save() {
+ ConfigurationManager mm = ConfigurationManager.getInstance();
+ if (configuration != null) {
+ configuration.setInternal(this);
+ mm.configurationChanged(configuration);
+ } else {
+ configuration = new Configuration();
+ configuration.setInternal(this);
+ mm.addConfiguration(configuration);
+ }
+ return configuration;
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfiguration.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfiguration.java
new file mode 100644
index 0000000..c6d44bf
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfiguration.java
@@ -0,0 +1,34 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+/**
+ *
+ */
+public interface IConfiguration {
+ public String getId();
+
+ public String getName();
+
+ public String getURL();
+
+ public String getType();
+
+ public String getPassword();
+
+ public String getUser();
+
+ public IConfigurationWorkingCopy getWorkingCopy();
+
+ public boolean isActive();
+
+ public void delete();
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationListener.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationListener.java
new file mode 100644
index 0000000..e44b5f6
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationListener.java
@@ -0,0 +1,21 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+/**
+ *
+ */
+public interface IConfigurationListener {
+ public void configurationAdded(IConfiguration monitor);
+
+ public void configurationChanged(IConfiguration monitor);
+
+ public void configurationRemoved(IConfiguration monitor);
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationWorkingCopy.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationWorkingCopy.java
new file mode 100644
index 0000000..1da0389
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationWorkingCopy.java
@@ -0,0 +1,29 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+/**
+ *
+ */
+public interface IConfigurationWorkingCopy extends IConfiguration {
+ public void setId(String id);
+
+ public void setName(String name);
+
+ public void setURL(String url);
+
+ public void setPassword(String port);
+
+ public void setUser(String port);
+
+ public void setType(String type);
+
+ public IConfiguration save();
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IMemento.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IMemento.java
new file mode 100644
index 0000000..2b6a743
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IMemento.java
@@ -0,0 +1,195 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+
+import java.util.List;
+
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IPersistableElement;
+/**
+ * Interface to a memento used for saving the important state of an object
+ * in a form that can be persisted in the file system.
+ *
+ *
+ *
+ * Mementos meet these requirements by providing support for storing a + * mapping of arbitrary string keys to primitive values, and by allowing + * mementos to have other mementos as children (arranged into a tree). + * A robust external storage format based on XML is used. + *
+ * The key for an attribute may be any alpha numeric value. However, the
+ * value of TAG_ID
is reserved for internal use.
+ *
+ * This interface is not intended to be implemented by clients. + *
+ * + * @see IPersistableElement + * @see IElementFactory + */ +public interface IMemento { + /** + * Special reserved key used to store the memento id + * (value"org.eclipse.ui.id"
).
+ *
+ * @see #getId
+ */
+ public static final String TAG_ID = "IMemento.internal.id"; //$NON-NLS-1$
+
+ /**
+ * Creates a new child of this memento with the given fType.
+ *
+ * The getChild
and getChildren
methods
+ * are used to retrieve children of a given fType.
+ *
TAG_ID
) and can be retrieved using getId
.
+ *
+ * The getChild
and getChildren
methods
+ * are used to retrieve children of a given fType.
+ *
null
if the key was not found or was found
+ * but was not a floating point number
+ */
+ public Float getFloat(String key);
+
+ /**
+ * Returns the id for this memento.
+ *
+ * @return the memento id, or null
if none
+ * @see #createChild(java.lang.String,java.lang.String)
+ */
+ public String getId();
+
+ /**
+ * Returns the name for this memento.
+ *
+ * @return the memento name, or null
if none
+ * @see #createChild(java.lang.String,java.lang.String)
+ */
+ public String getName();
+
+ /**
+ * Returns the integer value of the given key.
+ *
+ * @param key the key
+ * @return the value, or null
if the key was not found or was found
+ * but was not an integer
+ */
+ public Integer getInteger(String key);
+
+ /**
+ * Returns the string value of the given key.
+ *
+ * @param key the key
+ * @return the value, or null
if the key was not found or was found
+ * but was not an integer
+ */
+ public String getString(String key);
+
+ /**
+ * Returns the boolean value of the given key.
+ *
+ * @param key the key
+ * @return the value, or null
if the key was not found or was found
+ * but was not a boolean
+ */
+ public Boolean getBoolean(String key);
+
+ public List getNames();
+
+ /**
+ * Sets the value of the given key to the given floating point number.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putFloat(String key, float value);
+
+ /**
+ * Sets the value of the given key to the given integer.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putInteger(String key, int value);
+
+ /**
+ * Sets the value of the given key to the given boolean value.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putBoolean(String key, boolean value);
+
+ /**
+ * Copy the attributes and children from memento
+ * to the receiver.
+ *
+ * @param memento the IMemento to be copied.
+ */
+ public void putMemento(IMemento memento);
+
+ /**
+ * Sets the value of the given key to the given string.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putString(String key, String value);
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/XMLMemento.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/XMLMemento.java
new file mode 100644
index 0000000..dc1954d
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/XMLMemento.java
@@ -0,0 +1,471 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.config;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+/**
+ * A Memento is a class independent container for persistence
+ * info. It is a reflection of 3 storage requirements.
+ *
+ * 1) We need the ability to persist an object and restore it.
+ * 2) The class for an object may be absent. If so we would
+ * like to skip the object and keep reading.
+ * 3) The class for an object may change. If so the new class
+ * should be able to read the old persistence info.
+ *
+ * We could ask the objects to serialize themselves into an
+ * ObjectOutputStream, DataOutputStream, or Hashtable. However
+ * all of these approaches fail to meet the second requirement.
+ *
+ * Memento supports binary persistance with a version ID.
+ */
+public final class XMLMemento implements IMemento {
+ private Document factory;
+ private Element element;
+
+ /**
+ * Answer a memento for the document and element. For simplicity
+ * you should use createReadRoot and createWriteRoot to create the initial
+ * mementos on a document.
+ */
+ public XMLMemento(Document doc, Element el) {
+ factory = doc;
+ element = el;
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public IMemento createChild(String type) {
+ Element child = factory.createElement(type);
+ element.appendChild(child);
+ return new XMLMemento(factory, child);
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public IMemento createChild(String type, String id) {
+ Element child = factory.createElement(type);
+ child.setAttribute(TAG_ID, id);
+ element.appendChild(child);
+ return new XMLMemento(factory, child);
+ }
+
+ /**
+ * Create a Document from a Reader and answer a root memento for reading
+ * a document.
+ */
+ protected static XMLMemento createReadRoot(Reader reader) {
+ Document document = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ document = parser.parse(new InputSource(reader));
+ Node node = document.getFirstChild();
+ if (node instanceof Element)
+ return new XMLMemento(document, (Element) node);
+ } catch (ParserConfigurationException e) {
+ } catch (IOException e) {
+ } catch (SAXException e) {
+ } finally {
+ try {
+ reader.close();
+ } catch (Exception e) { }
+ }
+ return null;
+ }
+
+ /**
+ * Answer a root memento for writing a document.
+ */
+ public static XMLMemento createWriteRoot(String type) {
+ Document document;
+ try {
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element element = document.createElement(type);
+ document.appendChild(element);
+ return new XMLMemento(document, element);
+ } catch (ParserConfigurationException e) {
+ throw new Error(e);
+ }
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public IMemento getChild(String type) {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return null;
+
+ // Find the first node which is a child of this node.
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (element2.getNodeName().equals(type))
+ return new XMLMemento(factory, element2);
+ }
+ }
+
+ // A child was not found.
+ return null;
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public IMemento [] getChildren(String type) {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return new IMemento[0];
+
+ // Extract each node with given fType.
+ ArrayList list = new ArrayList(size);
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (element2.getNodeName().equals(type))
+ list.add(element2);
+ }
+ }
+
+ // Create a memento for each node.
+ size = list.size();
+ IMemento [] results = new IMemento[size];
+ for (int x = 0; x < size; x ++) {
+ results[x] = new XMLMemento(factory, (Element)list.get(x));
+ }
+ return results;
+ }
+
+ /**
+ * Return the contents of this memento as a byte array.
+ *
+ * @return byte[]
+ */
+ public byte[] getContents() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return out.toByteArray();
+ }
+
+ /**
+ * Returns an input stream for writing to the disk with a local locale.
+ *
+ * @return java.io.InputStream
+ */
+ public InputStream getInputStream() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return new ByteArrayInputStream(out.toByteArray());
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public Float getFloat(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ try {
+ return new Float(strValue);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public String getId() {
+ return element.getAttribute(TAG_ID);
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public String getName() {
+ return element.getNodeName();
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public Integer getInteger(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ try {
+ return new Integer(strValue);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public String getString(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ return attr.getValue();
+ }
+
+ public List getNames() {
+ NamedNodeMap map = element.getAttributes();
+ int size = map.getLength();
+ List list = new ArrayList();
+ for (int i = 0; i < size; i++) {
+ Node node = map.item(i);
+ String name = node.getNodeName();
+ list.add(name);
+ }
+ return list;
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param in java.io.InputStream
+ * @return org.eclipse.ui.IMemento
+ * @exception java.io.IOException
+ */
+ public static IMemento loadMemento(InputStream in) {
+ return createReadRoot(new InputStreamReader(in));
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param in java.io.InputStream
+ * @return org.eclipse.ui.IMemento
+ * @exception java.io.IOException
+ */
+ public static IMemento loadCorruptMemento(InputStream in) {
+ Document document = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ document = parser.parse(in);
+ Node node = document.getFirstChild();
+ if (node instanceof Element)
+ return new XMLMemento(document, (Element) node);
+ } catch (ParserConfigurationException e) {
+ } catch (IOException e) {
+ } catch (SAXException e) {
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) { }
+ }
+ return null;
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param filename java.lang.String
+ * @return org.eclipse.ui.IMemento
+ * @exception java.io.IOException
+ */
+ public static IMemento loadMemento(String filename) throws IOException {
+ return XMLMemento.createReadRoot(new FileReader(filename));
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param url java.net.URL
+ * @return org.eclipse.ui.IMemento
+ * @exception java.io.IOException
+ */
+ public static IMemento loadMemento(URL url) throws IOException {
+ return XMLMemento.createReadRoot(new InputStreamReader(url.openStream()));
+ }
+
+ /**
+ * @see IMemento.
+ */
+ private void putElement(Element element2) {
+ NamedNodeMap nodeMap = element2.getAttributes();
+ int size = nodeMap.getLength();
+ for (int i = 0; i < size; i++){
+ Attr attr = (Attr)nodeMap.item(i);
+ putString(attr.getName(),attr.getValue());
+ }
+
+ NodeList nodes = element2.getChildNodes();
+ size = nodes.getLength();
+ for (int i = 0; i < size; i ++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element) {
+ XMLMemento child = (XMLMemento)createChild(node.getNodeName());
+ child.putElement((Element)node);
+ }
+ }
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public void putFloat(String key, float f) {
+ element.setAttribute(key, String.valueOf(f));
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public void putInteger(String key, int n) {
+ element.setAttribute(key, String.valueOf(n));
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public void putMemento(IMemento memento) {
+ XMLMemento xmlMemento = (XMLMemento) memento;
+ putElement(xmlMemento.element);
+ }
+
+ /**
+ * @see IMemento.
+ */
+ public void putString(String key, String value) {
+ if (value == null)
+ return;
+ element.setAttribute(key, value);
+ }
+
+ /**
+ * Save this Memento to a Writer.
+ */
+ public void save(Writer writer) throws IOException {
+ Result result = new StreamResult(writer);
+ Source source = new DOMSource(factory);
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.transform(source, result);
+ } catch (Exception e) {
+ throw (IOException) (new IOException().initCause(e));
+ }
+ }
+
+ /**
+ * Save this Memento to a Writer.
+ */
+ public void save(OutputStream os) throws IOException {
+ Result result = new StreamResult(os);
+ Source source = new DOMSource(factory);
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.transform(source, result);
+ } catch (Exception e) {
+ throw (IOException) (new IOException().initCause(e));
+ }
+ }
+
+ /**
+ * Saves the memento to the given file.
+ *
+ * @param filename java.lang.String
+ * @exception java.io.IOException
+ */
+ public void saveToFile(String filename) throws IOException {
+ Writer w = null;
+ try {
+ w = new FileWriter(filename);
+ save(w);
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException(e.getLocalizedMessage());
+ } finally {
+ if (w != null) {
+ try {
+ w.close();
+ } catch (Exception e) { }
+ }
+ }
+ }
+
+ public String saveToString() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return out.toString("UTF-8");
+ }
+
+ /*
+ * @see IMemento#getBoolean(String)
+ */
+ public Boolean getBoolean(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ if ("true".equalsIgnoreCase(strValue))
+ return new Boolean(true);
+ else
+ return new Boolean(false);
+ }
+
+ /*
+ * @see IMemento#putBoolean(String, boolean)
+ */
+ public void putBoolean(String key, boolean value) {
+ element.setAttribute(key, value ? "true" : "false");
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationComposite.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationComposite.java
new file mode 100644
index 0000000..023b508
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationComposite.java
@@ -0,0 +1,208 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.preferences;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sourceforge.phpdt.httpquery.config.IConfiguration;
+import net.sourceforge.phpdt.httpquery.config.IConfigurationWorkingCopy;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+/**
+ *
+ */
+public class ConfigurationComposite extends Composite {
+ protected Table table;
+ protected TableViewer tableViewer;
+
+ protected Button edit;
+ protected Button remove;
+// protected Button start;
+// protected Button stop;
+
+ protected List selection2;
+
+ public ConfigurationComposite(Composite parent, int style) {
+ super(parent, style);
+
+ createWidgets();
+ }
+
+ protected void createWidgets() {
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = 6;
+ layout.verticalSpacing = 6;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.numColumns = 2;
+ setLayout(layout);
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ setLayoutData(data);
+
+ Label label = new Label(this, SWT.WRAP);
+ label.setText(PHPHelpPlugin.getResource("%configurationsList"));
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
+
+ label = new Label(this, SWT.NONE);
+
+ table = new Table(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ data.widthHint = 300;
+ data.heightHint = 300;
+// WorkbenchHelp.setHelp(table, ContextIds.PREF_MONITORS);
+
+ table.setLayoutData(data);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ TableLayout tableLayout = new TableLayout();
+
+ TableColumn statusColumn = new TableColumn(table, SWT.NONE);
+ statusColumn.setText(PHPHelpPlugin.getResource("%columnName"));
+ ColumnWeightData colData = new ColumnWeightData(5, 30, true);
+ tableLayout.addColumnData(colData);
+
+ TableColumn typeColumn = new TableColumn(table, SWT.NONE);
+ typeColumn.setText(PHPHelpPlugin.getResource("%columnType"));
+ colData = new ColumnWeightData(5, 30, true);
+ tableLayout.addColumnData(colData);
+
+ TableColumn urlColumn = new TableColumn(table, SWT.NONE);
+ urlColumn.setText(PHPHelpPlugin.getResource("%columnUser"));
+ colData = new ColumnWeightData(5, 30, true);
+ tableLayout.addColumnData(colData);
+
+ TableColumn localColumn = new TableColumn(table, SWT.NONE);
+ localColumn.setText(PHPHelpPlugin.getResource("%columnURL"));
+ colData = new ColumnWeightData(5, 150, true);
+ tableLayout.addColumnData(colData);
+
+ table.setLayout(tableLayout);
+
+ tableViewer = new TableViewer(table);
+ tableViewer.setContentProvider(new ConfigurationContentProvider());
+ tableViewer.setLabelProvider(new ConfigurationTableLabelProvider());
+ tableViewer.setInput("root");
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ setSelection(event.getSelection());
+ }
+ });
+
+ Composite buttonComp = new Composite(this, SWT.NONE);
+ layout = new GridLayout();
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 8;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.numColumns = 1;
+ buttonComp.setLayout(layout);
+ data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL);
+ buttonComp.setLayoutData(data);
+
+ Button add = SWTUtil.createButton(buttonComp, PHPHelpPlugin.getResource("%add"));
+ add.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ ConfigurationDialog dialog = new ConfigurationDialog(getShell());
+ if (dialog.open() == Window.CANCEL)
+ return;
+ tableViewer.refresh();
+
+ List list = PHPHelpPlugin.getConfigurations();
+ Object configuration = list.get(list.size() - 1);
+ tableViewer.setSelection(new StructuredSelection(configuration));
+ }
+ });
+
+ edit = SWTUtil.createButton(buttonComp, PHPHelpPlugin.getResource("%edit"));
+ edit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IConfiguration monitor = (IConfiguration) getSelection().get(0);
+ IConfigurationWorkingCopy wc = monitor.getWorkingCopy();
+
+ ConfigurationDialog dialog = new ConfigurationDialog(getShell(), wc);
+ if (dialog.open() != Window.CANCEL) {
+ try {
+ tableViewer.refresh(wc.save());
+ } catch (Exception ex) { }
+ }
+ }
+ });
+ edit.setEnabled(false);
+
+ remove = SWTUtil.createButton(buttonComp, PHPHelpPlugin.getResource("%remove"));
+ remove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ Iterator iterator = getSelection().iterator();
+ while (iterator.hasNext()) {
+ IConfiguration monitor = (IConfiguration) iterator.next();
+ try {
+ monitor.delete();
+ } catch (Exception ex) { }
+ tableViewer.remove(monitor);
+
+ List list = PHPHelpPlugin.getConfigurations();
+ Object monitor2 = list.get(list.size() - 1);
+ tableViewer.setSelection(new StructuredSelection(monitor2));
+ }
+ }
+ });
+ remove.setEnabled(false);
+
+ }
+
+ protected List getSelection() {
+ return selection2;
+ }
+
+ protected void setSelection(ISelection sel2) {
+ IStructuredSelection sel = (IStructuredSelection) sel2;
+ Iterator iterator = sel.iterator();
+ selection2 = new ArrayList();
+
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (obj instanceof IConfiguration)
+ selection2.add(obj);
+ }
+
+ if (!selection2.isEmpty()) {
+ remove.setEnabled(true);
+
+ edit.setEnabled(true);
+ } else {
+ edit.setEnabled(false);
+ remove.setEnabled(false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationContentProvider.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationContentProvider.java
new file mode 100644
index 0000000..0fd236f
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationContentProvider.java
@@ -0,0 +1,81 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.preferences;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sourceforge.phpdt.httpquery.config.IConfiguration;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Configuration content provider.
+ */
+public class ConfigurationContentProvider implements IStructuredContentProvider {
+ /**
+ * ConfigurationContentProvider constructor comment.
+ */
+ public ConfigurationContentProvider() {
+ super();
+ }
+
+ /**
+ * Disposes of this content provider. This is called by the viewer when it is
+ * disposed.
+ */
+ public void dispose() {
+ }
+
+ /**
+ * Returns the elements to display in the viewer when its input is set to the
+ * given element. These elements can be presented as rows in a table, items in
+ * a list, etc. The result is not modified by the viewer.
+ *
+ * @param inputElement
+ * the input element
+ * @return the array of elements to display in the viewer
+ */
+ public Object[] getElements(Object inputElement) {
+ List list = new ArrayList();
+ Iterator iterator = PHPHelpPlugin.getConfigurations().iterator();
+ while (iterator.hasNext()) {
+ IConfiguration configuration = (IConfiguration) iterator.next();
+ list.add(configuration);
+ }
+ return list.toArray();
+ }
+
+ /**
+ * Notifies this content provider that the given viewer's input has been
+ * switched to a different element.
+ * + * A typical use for this method is registering the content provider as a + * listener to changes on the new input (using model-specific means), and + * deregistering the viewer from the old input. In response to these change + * notifications, the content provider propagates the changes to the viewer. + *
+ * + * @param viewer + * the viewer + * @param oldInput + * the old input element, ornull
if the viewer did
+ * not previously have an input
+ * @param newInput
+ * the new input element, or null
if the viewer does
+ * not have an input
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationDialog.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationDialog.java
new file mode 100644
index 0000000..68e2e22
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationDialog.java
@@ -0,0 +1,260 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ �*
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.preferences;
+
+import java.util.ArrayList;
+
+import net.sourceforge.phpdt.httpquery.config.IConfigurationWorkingCopy;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ *
+ */
+public class ConfigurationDialog extends Dialog {
+ protected IConfigurationWorkingCopy fConfiguration;
+
+ protected boolean isEdit;
+
+ private Button okButton;
+
+ private Text fUserName;
+
+ private Text fUrl;
+
+ private Text fPassword;
+
+ interface StringModifyListener {
+ public void valueChanged(String s);
+ }
+
+ interface BooleanModifyListener {
+ public void valueChanged(boolean b);
+ }
+
+ interface TypeModifyListener {
+ public void valueChanged(String fType);
+ }
+
+ /**
+ * @param parentShell
+ */
+ public ConfigurationDialog(Shell parentShell, IConfigurationWorkingCopy configuration) {
+ super(parentShell);
+ this.fConfiguration = configuration;
+ isEdit = true;
+ }
+
+ public ConfigurationDialog(Shell parentShell) {
+ super(parentShell);
+ fConfiguration = PHPHelpPlugin.createConfiguration();
+ isEdit = false;
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ if (isEdit)
+ shell.setText(PHPHelpPlugin.getResource("%editConfig"));
+ else
+ shell.setText(PHPHelpPlugin.getResource("%newConfig"));
+ }
+
+ protected Label createLabel(Composite comp, String txt) {
+ Label label = new Label(comp, SWT.NONE);
+ label.setText(txt);
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
+ return label;
+ }
+
+ protected Text createPassword(Composite comp, String txt, final StringModifyListener listener) {
+ final Text text = new Text(comp, SWT.BORDER | SWT.PASSWORD);
+ if (txt != null)
+ text.setText(txt);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.widthHint = 150;
+ text.setLayoutData(data);
+ if (listener != null)
+ text.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ listener.valueChanged(text.getText());
+ }
+ });
+ return text;
+ }
+
+ protected Text createText(Composite comp, String txt, final StringModifyListener listener) {
+ final Text text = new Text(comp, SWT.BORDER);
+ if (txt != null)
+ text.setText(txt);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.widthHint = 150;
+ text.setLayoutData(data);
+ if (listener != null)
+ text.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ listener.valueChanged(text.getText());
+ }
+ });
+ return text;
+ }
+
+ protected Combo createTypeCombo(Composite comp, final ArrayList types, String sel, final TypeModifyListener listener) {
+ final Combo combo = new Combo(comp, SWT.DROP_DOWN | SWT.READ_ONLY);
+ int size = types.size();
+ String[] items = new String[size];
+ int index = -1;
+ for (int i = 0; i < size; i++) {
+ items[i] = (String)types.get(i);
+ if (items[i].equals(sel))
+ index = i;
+ }
+ combo.setItems(items);
+ if (index >= 0)
+ combo.select(index);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.widthHint = 150;
+ combo.setLayoutData(data);
+ if (listener != null)
+ combo.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ listener.valueChanged((String)types.get(combo.getSelectionIndex()));
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+ return combo;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ ((GridLayout) composite.getLayout()).numColumns = 2;
+
+ // WorkbenchHelp.setHelp(composite, ContextIds.PREF_DIALOG);
+
+ createLabel(composite, PHPHelpPlugin.getResource("%name"));
+ fUserName = createText(composite, fConfiguration.getName() + "", new StringModifyListener() {
+ public void valueChanged(String name) {
+ fConfiguration.setName(name);
+ validateFields();
+ }
+ });
+
+ Group group = new Group(composite, SWT.NONE);
+ GridLayout layout = new GridLayout(2, false);
+ group.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+
+ group.setLayoutData(data);
+ group.setText(PHPHelpPlugin.getResource("%configGroup"));
+
+ createLabel(group, PHPHelpPlugin.getResource("%user"));
+ fUserName = createText(group, fConfiguration.getUser() + "", new StringModifyListener() {
+ public void valueChanged(String s) {
+ fConfiguration.setUser(s);
+ validateFields();
+ }
+ });
+
+ Composite warningComposite = new Composite(group, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginHeight = 0;
+ warningComposite.setLayout(layout);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 3;
+ warningComposite.setLayoutData(data);
+ Label warningLabel = new Label(warningComposite, SWT.NONE);
+ warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING));
+ warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
+ Label warningText = new Label(warningComposite, SWT.WRAP);
+ warningText.setText(PHPHelpPlugin.getResource("%scrambledPassword")); //$NON-NLS-1$
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = 300;
+ warningText.setLayoutData(data);
+
+ createLabel(group, PHPHelpPlugin.getResource("%password"));
+ fPassword = createPassword(group, fConfiguration.getPassword() + "", new StringModifyListener() {
+ public void valueChanged(String s) {
+ fConfiguration.setPassword(s);
+ validateFields();
+ }
+ });
+
+ createLabel(group, PHPHelpPlugin.getResource("%url"));
+ fUrl = createText(group, fConfiguration.getURL(), new StringModifyListener() {
+ public void valueChanged(String s) {
+ fConfiguration.setURL(s);
+ validateFields();
+ }
+ });
+
+ createLabel(group, PHPHelpPlugin.getResource("%parseType"));
+ createTypeCombo(group, PHPHelpPlugin.getTypes(), fConfiguration.getType(), new TypeModifyListener() {
+ public void valueChanged(String fType) {
+ fConfiguration.setType(fType);
+ }
+ });
+
+ return composite;
+ }
+
+ protected void okPressed() {
+ fConfiguration.save();
+ super.okPressed();
+ }
+
+ protected Control createButtonBar(Composite parent) {
+ Control buttonControl = super.createButtonBar(parent);
+ validateFields();
+ return buttonControl;
+ }
+
+ private void setOKButtonEnabled(boolean curIsEnabled) {
+ if (okButton == null)
+ okButton = getButton(IDialogConstants.OK_ID);
+
+ if (okButton != null)
+ okButton.setEnabled(curIsEnabled);
+ }
+
+ protected void validateFields() {
+ boolean result = true;
+
+ setOKButtonEnabled(result);
+ }
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencePage.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencePage.java
new file mode 100644
index 0000000..ad23c6f
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencePage.java
@@ -0,0 +1,107 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.preferences;
+
+
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+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.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+/**
+ * The preference page that holds monitor properties.
+ */
+public class ConfigurationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ /**
+ * ConfigurationPreferencePage constructor comment.
+ */
+ public ConfigurationPreferencePage() {
+ super();
+ noDefaultAndApplyButton();
+ }
+
+ /**
+ * Create the preference options.
+ *
+ * @param parent org.eclipse.swt.widgets.Composite
+ * @return org.eclipse.swt.widgets.Control
+ */
+ protected Control createContents(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(4);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ composite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ composite.setLayoutData(data);
+// WorkbenchHelp.setHelp(composite, ContextIds.PREF);
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText(PHPHelpPlugin.getResource("%preferenceDescription"));
+ data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+ label.setLayoutData(data);
+
+ label = new Label(composite, SWT.NONE);
+ label.setText("");
+
+ ConfigurationComposite monitorComp = new ConfigurationComposite(composite, SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+ monitorComp.setLayoutData(data);
+
+ Dialog.applyDialogFont(composite);
+
+ return composite;
+ }
+
+ /**
+ * Initializes this preference page using the passed desktop.
+ *
+ * @param desktop the current desktop
+ */
+ public void init(IWorkbench workbench) {
+ }
+
+ /**
+ * Performs special processing when this page's Defaults button has been pressed.
+ *
+ * This is a framework hook method for sublcasses to do special things when
+ * the Defaults button has been pressed.
+ * Subclasses may override, but should call super.performDefaults
.
+ *
+ * Label provider listeners are informed about state changes that affect the rendering of the viewer that uses this label + * provider. + *
+ * + * @param listener + * a label provider listener + */ + public void addListener(ILabelProviderListener listener) { + } + + /** + * Disposes of this label provider. When a label provider is attached to a viewer, the viewer will automatically call this method + * when the viewer is being closed. When label providers are used outside of the context of a viewer, it is the client's + * responsibility to ensure that this method is called when the provider is no longer needed. + */ + public void dispose() { + } + + /** + * Returns the label image for the given column of the given element. + * + * @param element + * the object representing the entire row, ornull
indicating that no input object is set in the viewer
+ * @param columnIndex
+ * the zero-based index of the column in which the label appears
+ */
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ /**
+ * Returns the label text for the given column of the given element.
+ *
+ * @param element
+ * the object representing the entire row, or null
indicating that no input object is set in the viewer
+ * @param columnIndex
+ * the zero-based index of the column in which the label appears
+ */
+ public String getColumnText(Object element, int columnIndex) {
+ IConfiguration configuration = (IConfiguration) element;
+ if (columnIndex == 0) {
+ return configuration.getName();
+ } else if (columnIndex == 1)
+ return configuration.getType();
+ else if (columnIndex == 2)
+ return configuration.getUser();
+ else if (columnIndex == 3)
+ return configuration.getURL();
+ else
+ return "X";
+ }
+
+ protected String notNull(String s) {
+ if (s != null)
+ return s;
+ else
+ return "";
+ }
+
+ /**
+ * Returns whether the label would be affected by a change to the given property of the given element. This can be used to
+ * optimize a non-structural viewer update. If the property mentioned in the update does not affect the label, then the viewer
+ * need not update the label.
+ *
+ * @param element
+ * the element
+ * @param property
+ * the property
+ * @return true
if the label would be affected, and false
if it would be unaffected
+ */
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ /**
+ * Removes a listener to this label provider. Has no affect if an identical listener is not registered.
+ *
+ * @param listener
+ * a label provider listener
+ */
+ public void removeListener(ILabelProviderListener listener) {
+ }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/SWTUtil.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/SWTUtil.java
new file mode 100644
index 0000000..2701b21
--- /dev/null
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/SWTUtil.java
@@ -0,0 +1,77 @@
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package net.sourceforge.phpdt.httpquery.preferences;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+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.Label;
+/**
+ * SWT Utility class.
+ */
+public class SWTUtil {
+ private static FontMetrics fontMetrics;
+
+ protected static void initializeDialogUnits(Control testControl) {
+ // Compute and store a font metric
+ GC gc = new GC(testControl);
+ gc.setFont(JFaceResources.getDialogFont());
+ fontMetrics = gc.getFontMetrics();
+ gc.dispose();
+ }
+
+ /**
+ * Returns a width hint for a button control.
+ */
+ protected static int getButtonWidthHint(Button button) {
+ int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
+ return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
+ }
+
+ public static Button createButton(Composite comp, String label) {
+ Button b = new Button(comp, SWT.PUSH);
+ b.setText(label);
+ if (fontMetrics == null)
+ initializeDialogUnits(comp);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.widthHint = getButtonWidthHint(b);
+ data.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT);
+ b.setLayoutData(data);
+ return b;
+ }
+
+ public static Button createCheckbox(Composite comp, String txt, boolean isSelected){
+ Button button = new Button(comp, SWT.CHECK);
+ button.setText(txt);
+ GridLayout layout = new GridLayout();
+ comp.setLayout(layout);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.horizontalIndent = 10;
+ button.setLayoutData(data);
+ button.setSelection(isSelected);
+ return button;
+ }
+
+ public static Label createLabel(Composite comp, String txt) {
+ Label label = new Label(comp, SWT.NONE);
+ label.setText(txt);
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
+ return label;
+ }
+}
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java
index f296936..3c24502 100644
--- a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java
+++ b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java
@@ -11,6 +11,12 @@
**********************************************************************/
package net.sourceforge.phpdt.phphelp;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.phpdt.httpquery.config.ConfigurationManager;
+import net.sourceforge.phpdt.httpquery.config.IConfigurationWorkingCopy;
+
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
@@ -35,6 +41,20 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
public static final String PHP_CHM_COMMAND = "_php_chm_command";
+ public static final String HTTP_QUERY = "HTTP Query";
+
+ public final static String PREF_STRING_CONFIGURATIONS = "__configurations";
+
+ public final static String CONFIG_MEMENTO = ""
+ + ""net.sourceforge.phpeclipse.phphelp"
).
@@ -44,6 +64,7 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
// The shared instance.
private static PHPHelpPlugin plugin;
+ private static ConfigurationManager manager;
/**
* The constructor.
*/
@@ -71,8 +92,7 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
}
private IWorkbenchPage internalGetActivePage() {
- IWorkbenchWindow window = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
return window.getActivePage();
return null;
@@ -91,14 +111,12 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
}
public static void log(int severity, String message) {
- Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
- null);
+ Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
log(status);
}
public static void log(Throwable e) {
- log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
- "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
}
public static boolean isDebug() {
@@ -106,16 +124,14 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
}
protected void initializeDefaultPreferences(IPreferenceStore store) {
+ store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
// windows preferences:
String windowsSystem = Platform.getWS();
if (windowsSystem.equals(Platform.WS_WIN32)) {
store.setDefault(PHP_CHM_ENABLED, "false");
- store
- .setDefault(PHP_CHM_FILE,
- "c:\\wampp2\\php\\php_manual_en.chm");
- store.setDefault(PHP_CHM_COMMAND,
- "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
+ store.setDefault(PHP_CHM_FILE, "c:\\wampp2\\php\\php_manual_en.chm");
+ store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
} else {
store.setDefault(PHP_CHM_ENABLED, "false");
store.setDefault(PHP_CHM_FILE, "");
@@ -160,13 +176,10 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
// ColorManager.getDefault().dispose();
// }
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
public void start(BundleContext context) throws Exception {
super.start(context);
+
+ manager = ConfigurationManager.getInstance();
// IAdapterManager manager = Platform.getAdapterManager();
// manager.registerAdapters(new PHPElementAdapterFactory(),
// PHPElement.class);
@@ -181,13 +194,49 @@ public class PHPHelpPlugin extends AbstractUIPlugin {
// });
}
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
public void stop(BundleContext context) throws Exception {
// ColorManager.getDefault().dispose();
super.stop(context);
}
+
+ /**
+ * Returns the translated String found with the given key.
+ *
+ * @return java.lang.String
+ * @param key
+ * java.lang.String
+ */
+ public static String getResource(String key) {
+ try {
+ return Platform.getResourceString(getDefault().getBundle(), key);
+ } catch (Exception e) {
+ return key;
+ }
+ }
+
+ /**
+ * Return a list of all the existing configurations.
+ *
+ * @return java.util.List
+ */
+ public static List getConfigurations() {
+ return manager.getConfigurations();
+ }
+
+ /**
+ * Create a new monitor.
+ *
+ * @return working copy
+ */
+ public static IConfigurationWorkingCopy createConfiguration() {
+ return manager.createConfiguration();
+ }
+
+ public static ArrayList getTypes() {
+ return CONFIGURATION_TYPES;
+ }
+
+ public static void addType(String type) {
+ CONFIGURATION_TYPES.add(type);
+ }
}
\ No newline at end of file
--
1.7.1