Open PHP Help Online Manual in the browser / add other http querie for google and...
authoraxelcl <axelcl>
Thu, 6 Apr 2006 21:52:44 +0000 (21:52 +0000)
committeraxelcl <axelcl>
Thu, 6 Apr 2006 21:52:44 +0000 (21:52 +0000)
23 files changed:
net.sourceforge.phpeclipse.phphelp/plugin.properties
net.sourceforge.phpeclipse.phphelp/plugin.xml
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/AbstractHTTPQueryAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/GoogleAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/HTTPQueryAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/KodersAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/PHPHelpAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/Configuration.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationManager.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/ConfigurationWorkingCopy.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfiguration.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationListener.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IConfigurationWorkingCopy.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/IMemento.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/XMLMemento.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationComposite.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationContentProvider.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationDialog.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencePage.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencesDialog.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationTableLabelProvider.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/SWTUtil.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/phphelp/PHPHelpPlugin.java

index f40a103..75aab0a 100644 (file)
@@ -5,6 +5,7 @@ pluginName=PHP Help
 providerName=phpeclipse.de
 phphelpLabel=PHP Help
 phphelpFormat=Help (WIN_32 *.chm format)
+httpQuery=HTTP Query
 
 context.editingPHPSource.name= Editing PHP Source
 context.editingPHPSource.description= Editing PHP Source Context
@@ -13,3 +14,33 @@ category.source.name=Source
 category.source.description= PHP Source Actions
 ActionDefinition.contexthelp.name= Open PHP HTML help
 ActionDefinition.contexthelp.description= Open PHP HTML help in browser
+
+HTTPQuery.label=HTTP Query
+
+# --------------- General UI ---------------
+preferenceDescription=Configure HTTP Actions for your Wiki texts.
+configurationsList=Configurations
+columnName=Name
+columnId=Id
+columnUser=User Name
+columnURL=URL
+columnType=Type
+columnStatus=Active
+add=Add...
+edit=Edit...
+remove=Remove
+start=Activate
+stop=Deactivate
+started=True
+stopped=False
+
+newConfig=New Configuration
+editConfig=Edit Configuration
+
+name=Name:
+user=User:
+configGroup=Configuration
+id=Blog-Id
+url=URL:
+password=Password:
+parseType=Type:
\ No newline at end of file
index cde80a0..9ada7a3 100644 (file)
@@ -20,6 +20,7 @@
       <import plugin="org.eclipse.jface.text"/>
       <import plugin="org.eclipse.swt"/>
       <import plugin="net.sourceforge.phpeclipse"/>
+      <import plugin="net.sourceforge.phpeclipse.webbrowser"/>
       <import plugin="org.eclipse.ui.editors"/>
       <import plugin="org.eclipse.ui.workbench.texteditor"/>
    </requires>
             class="net.sourceforge.phpdt.phphelp.PHPHelpPreferencePage"
             id="net.sourceforge.phpdt.phphelp.PHPHelpPreferencePage">
       </page>
+      <page
+           name="%httpQuery"
+           category="net.sourceforge.phpeclipse.preferences.PHPPreferencePage"
+           class="net.sourceforge.phpdt.httpquery.preferences.ConfigurationPreferencePage"
+           id="net.sourceforge.phpdt.httpquery.preferences.configurationPreferencePage">
+      </page>
    </extension>
    <extension
          point="org.eclipse.ui.bindings">
             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
       </key>
    </extension>
+
+   <extension
+         point="org.eclipse.ui.popupMenus">
+     <viewerContribution
+            targetID="#PHPEditorContext"
+            id="net.sourceforge.phpdt.phphelp.actions.httpquery">
+           <menu
+                       id="httpqueryMenu"
+                       label="%HTTPQuery.label"
+                       path="rest">
+                </menu>
+                <action
+               label="Koders.com Search"
+               class="net.sourceforge.phpdt.httpquery.KodersAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.KodersAction">
+         </action>
+                <action
+               label="Google Search"
+               class="net.sourceforge.phpdt.httpquery.GoogleAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.GoogleAction">
+         </action>
+         <action
+               label="PHP Online Manual"
+               class="net.sourceforge.phpdt.httpquery.PHPHelpAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.PHPHelpAction">
+         </action>
+                <action
+               label="HTTP Query..."
+               class="net.sourceforge.phpdt.httpquery.HTTPQueryAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.HTTPQueryAction">
+         </action>
+      </viewerContribution>
+      <viewerContribution
+            targetID="#EditorContext"
+            id="net.sourceforge.phpeclipse.wiki.texteditor.viewercontribution">
+         <menu
+                       id="httpqueryMenu"
+                       label="%HTTPQuery.label"
+                       path="rest">
+                </menu>
+                <action
+               label="Koders.com Search"
+               class="net.sourceforge.phpdt.httpquery.KodersAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.KodersAction">
+         </action>
+                <action
+               label="Google Search"
+               class="net.sourceforge.phpdt.httpquery.GoogleAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.GoogleAction">
+         </action>
+                <action
+               label="HTTP Query..."
+               class="net.sourceforge.phpdt.httpquery.HTTPQueryAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpdt.httpquery.HTTPQueryAction">
+         </action>
+      </viewerContribution>
+  </extension>
 </plugin>
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/AbstractHTTPQueryAction.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/AbstractHTTPQueryAction.java
new file mode 100644 (file)
index 0000000..6d36486
--- /dev/null
@@ -0,0 +1,138 @@
+package net.sourceforge.phpdt.httpquery;
+
+import net.sourceforge.phpdt.httpquery.config.Configuration;
+import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
+
+       private AbstractTextEditor editor;
+
+       public AbstractHTTPQueryAction() {
+               super();
+       }
+
+       abstract protected Configuration getConfiguration();
+
+       public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+               if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+                       editor = (AbstractTextEditor) targetEditor;
+               }
+       }
+
+       public void run(IAction action) {
+               IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+               if (editor == null) {
+                       IEditorPart targetEditor = window.getActivePage().getActiveEditor();
+                       if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+                               editor = (AbstractTextEditor) targetEditor;
+                       }
+               }
+
+               if (window != null) {
+                       IWorkbenchPage page = window.getActivePage();
+                       try {
+                               IViewPart part = page.findView(BrowserView.ID_BROWSER);
+                               if (part == null) {
+                                       part = page.showView(BrowserView.ID_BROWSER);
+                               } else {
+                                       page.bringToTop(part);
+                               }
+                               Configuration config = getConfiguration();
+                               String templateString = generateUrl(config, config.getURL());
+                               if (templateString != null && !templateString.equals("")) {
+                                       ((BrowserView) part).setUrl(templateString);
+                               }
+                       } catch (Exception e) {
+                       }
+               }
+       }
+
+       public void selectionChanged(IAction action, ISelection selection) {
+       }
+
+       public IDocument getDocument() {
+               IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
+               return doc;
+       }
+
+       public static String getSelectedText(AbstractTextEditor editor, IDocument document, int initialPos) {
+               try {
+                       int pos = initialPos;
+                       int line = document.getLineOfOffset(pos);
+                       int start = document.getLineOffset(line);
+                       int end = start + document.getLineInformation(line).getLength();
+
+                       /*
+                        * The line does not include \n or \r so pos can be > end. Making pos =
+                        * end in this case is safe for the purposes of determining the TextRegion
+                        * at the cursor position
+                        */
+                       if (pos > end) {
+                               pos = end;
+                       }
+
+                       int offsetInLine = pos - start;
+                       String word = document.get(start, end - start);
+                       int wordlen = word.length();
+                       int textStart = -1;
+                       int textEnd = -1;
+
+                       for (int i = offsetInLine; i < wordlen; i++) {
+                               if (!Character.isJavaIdentifierPart(word.charAt(i))) {
+                                       textEnd = i;
+                                       break;
+                               }
+                       }
+                       for (int i = offsetInLine; i >= 0; i--) {
+                               if (!Character.isJavaIdentifierPart(word.charAt(i))) {
+                                       textStart = i + 1;
+                                       break;
+                               }
+                       }
+                       if (textStart != (-1) && textEnd != (-1) && textStart < textEnd) {
+                               return new String(word.toCharArray(), textStart, textEnd - textStart);
+                       }
+               } catch (Exception e) {
+
+               }
+               return null;
+       }
+
+       public String generateUrl(Configuration config, String template) {
+               IDocument doc = getDocument();
+               ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
+               int pos = selection.getOffset();
+               int len = selection.getLength();
+               String wikiTitle;
+               if (len > 0) {
+                       try {
+                               wikiTitle = doc.get(pos, len);
+                       } catch (BadLocationException e) {
+                               wikiTitle = null;
+                       }
+               } else {
+                       wikiTitle = getSelectedText(editor, doc, pos);
+               }
+
+               if (wikiTitle != null && !wikiTitle.equals("")) {
+                       template = template.replaceAll("\\$text.selection", wikiTitle);
+                       wikiTitle = wikiTitle.replaceAll("_", "-");
+                       template = template.replaceAll("\\$php.selection", wikiTitle);
+                       return template;
+               }
+               return null;
+       }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/GoogleAction.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/GoogleAction.java
new file mode 100644 (file)
index 0000000..e555929
--- /dev/null
@@ -0,0 +1,22 @@
+package net.sourceforge.phpdt.httpquery;
+
+import net.sourceforge.phpdt.httpquery.config.Configuration;
+import net.sourceforge.phpdt.httpquery.config.ConfigurationWorkingCopy;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+
+public class GoogleAction extends AbstractHTTPQueryAction {
+
+  public GoogleAction() {
+    super();
+  }
+
+  protected Configuration getConfiguration() {
+    ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
+    config.setName("Google Search");
+    config.setURL("http://www.google.com/search?q=$text.selection");
+    config.setType(PHPHelpPlugin.HTTP_QUERY);
+    return config;
+  }
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/HTTPQueryAction.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/HTTPQueryAction.java
new file mode 100644 (file)
index 0000000..50dce47
--- /dev/null
@@ -0,0 +1,50 @@
+package net.sourceforge.phpdt.httpquery;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import net.sourceforge.phpdt.httpquery.config.Configuration;
+import net.sourceforge.phpdt.httpquery.config.ConfigurationManager;
+import net.sourceforge.phpdt.httpquery.config.IConfiguration;
+import net.sourceforge.phpdt.internal.ui.viewsupport.ListContentProvider;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+
+public class HTTPQueryAction extends AbstractHTTPQueryAction {
+
+  public HTTPQueryAction() {
+    super();
+  }
+
+  protected Configuration getConfiguration() {
+    String selectedURL = null;
+
+    List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
+    ArrayList configsList = new ArrayList();
+    for (int i = 0; i < allConfigsList.size(); i++) {
+      IConfiguration temp = (IConfiguration) allConfigsList.get(i);
+      if (temp.getType().equals(PHPHelpPlugin.HTTP_QUERY)) {
+        configsList.add(temp);
+      }
+    }
+    Collections.sort(configsList);
+
+    ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPHelpPlugin.getDefault().getWorkbench()
+        .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(), "Select URL");
+    listSelectionDialog.setTitle("Multiple configuration found");
+    if (listSelectionDialog.open() == Window.OK) {
+      Object[] configurations = listSelectionDialog.getResult();
+      if (configurations != null) {
+        for (int i = 0; i < configurations.length; i++) {
+          return ((Configuration) configurations[i]); // .getURL();
+        }
+      }
+    }
+    return null;
+  }
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/KodersAction.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/KodersAction.java
new file mode 100644 (file)
index 0000000..a6b6a99
--- /dev/null
@@ -0,0 +1,21 @@
+package net.sourceforge.phpdt.httpquery;
+
+import net.sourceforge.phpdt.httpquery.config.Configuration;
+import net.sourceforge.phpdt.httpquery.config.ConfigurationWorkingCopy;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+
+public class KodersAction extends AbstractHTTPQueryAction {
+
+  public KodersAction() {
+    super();
+  }
+
+  protected Configuration getConfiguration() {
+    ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
+    config.setName("Koders.com Search");
+    config.setURL("http://koders.com/?s=$text.selection");
+    config.setType(PHPHelpPlugin.HTTP_QUERY);
+    return config;
+  }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/PHPHelpAction.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/PHPHelpAction.java
new file mode 100644 (file)
index 0000000..86878e9
--- /dev/null
@@ -0,0 +1,21 @@
+package net.sourceforge.phpdt.httpquery;
+
+import net.sourceforge.phpdt.httpquery.config.Configuration;
+import net.sourceforge.phpdt.httpquery.config.ConfigurationWorkingCopy;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+
+public class PHPHelpAction extends AbstractHTTPQueryAction {
+
+  public PHPHelpAction() {
+    super();
+  }
+
+  protected Configuration getConfiguration() {
+    ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
+    config.setName("PHP Online Manual");
+    config.setURL("http://www.php.net/manual/en/function.$php.selection.php");
+    config.setType(PHPHelpPlugin.HTTP_QUERY);
+    return config;
+  }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/Configuration.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/config/Configuration.java
new file mode 100644 (file)
index 0000000..98eb4d6
--- /dev/null
@@ -0,0 +1,484 @@
+/**********************************************************************
+ * 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 net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+
+/**
+ *
+ */
+public class Configuration implements IConfiguration, Comparable {
+  private static final String MEMENTO_ID = "id";
+
+  private static final String MEMENTO_NAME = "name";
+
+  private static final String MEMENTO_USER = "user";
+
+  private static final String MEMENTO_URL = "url";
+
+  private static final String MEMENTO_PASSWORD = "password";
+
+  private static final String MEMENTO_TYPE_ID = "type-id";
+
+  protected String fId = "";
+
+  protected String fName = "";
+
+  protected String fUrl = "";
+
+  protected String fPassword = "";
+
+  protected String fUser = "";
+
+  protected String fType = "";
+
+  private static final char[] SCRAMBLING_TABLE = new char[] {
+      0,
+      1,
+      2,
+      3,
+      4,
+      5,
+      6,
+      7,
+      8,
+      9,
+      10,
+      11,
+      12,
+      13,
+      14,
+      15,
+      16,
+      17,
+      18,
+      19,
+      20,
+      21,
+      22,
+      23,
+      24,
+      25,
+      26,
+      27,
+      28,
+      29,
+      30,
+      31,
+      114,
+      120,
+      53,
+      79,
+      96,
+      109,
+      72,
+      108,
+      70,
+      64,
+      76,
+      67,
+      116,
+      74,
+      68,
+      87,
+      111,
+      52,
+      75,
+      119,
+      49,
+      34,
+      82,
+      81,
+      95,
+      65,
+      112,
+      86,
+      118,
+      110,
+      122,
+      105,
+      41,
+      57,
+      83,
+      43,
+      46,
+      102,
+      40,
+      89,
+      38,
+      103,
+      45,
+      50,
+      42,
+      123,
+      91,
+      35,
+      125,
+      55,
+      54,
+      66,
+      124,
+      126,
+      59,
+      47,
+      92,
+      71,
+      115,
+      78,
+      88,
+      107,
+      106,
+      56,
+      36,
+      121,
+      117,
+      104,
+      101,
+      100,
+      69,
+      73,
+      99,
+      63,
+      94,
+      93,
+      39,
+      37,
+      61,
+      48,
+      58,
+      113,
+      32,
+      90,
+      44,
+      98,
+      60,
+      51,
+      33,
+      97,
+      62,
+      77,
+      84,
+      80,
+      85,
+      223,
+      225,
+      216,
+      187,
+      166,
+      229,
+      189,
+      222,
+      188,
+      141,
+      249,
+      148,
+      200,
+      184,
+      136,
+      248,
+      190,
+      199,
+      170,
+      181,
+      204,
+      138,
+      232,
+      218,
+      183,
+      255,
+      234,
+      220,
+      247,
+      213,
+      203,
+      226,
+      193,
+      174,
+      172,
+      228,
+      252,
+      217,
+      201,
+      131,
+      230,
+      197,
+      211,
+      145,
+      238,
+      161,
+      179,
+      160,
+      212,
+      207,
+      221,
+      254,
+      173,
+      202,
+      146,
+      224,
+      151,
+      140,
+      196,
+      205,
+      130,
+      135,
+      133,
+      143,
+      246,
+      192,
+      159,
+      244,
+      239,
+      185,
+      168,
+      215,
+      144,
+      139,
+      165,
+      180,
+      157,
+      147,
+      186,
+      214,
+      176,
+      227,
+      231,
+      219,
+      169,
+      175,
+      156,
+      206,
+      198,
+      129,
+      164,
+      150,
+      210,
+      154,
+      177,
+      134,
+      127,
+      182,
+      128,
+      158,
+      208,
+      162,
+      132,
+      167,
+      209,
+      149,
+      241,
+      153,
+      251,
+      237,
+      236,
+      171,
+      195,
+      243,
+      233,
+      253,
+      240,
+      194,
+      250,
+      191,
+      155,
+      142,
+      137,
+      245,
+      235,
+      163,
+      242,
+      178,
+      152 };
+
+  /**
+   * Construct a Configuration with the defult type:
+   * <code>net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY</code>
+   *
+   */
+  public Configuration() {
+    this(PHPHelpPlugin.HTTP_QUERY); // default type
+  }
+
+  /**
+   * Construct a Configuration with a type
+   * @param type Example: <code>net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY</code>
+   *
+   * @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 (file)
index 0000000..2b23dea
--- /dev/null
@@ -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 (file)
index 0000000..97742a3
--- /dev/null
@@ -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 (file)
index 0000000..c6d44bf
--- /dev/null
@@ -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 (file)
index 0000000..e44b5f6
--- /dev/null
@@ -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 (file)
index 0000000..1da0389
--- /dev/null
@@ -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 (file)
index 0000000..2b6a743
--- /dev/null
@@ -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.
+ * <p>
+ * Mementos were designed with the following requirements in mind:
+ * <ol>
+ *  <li>Certain objects need to be saved and restored across platform sessions.
+ *    </li>
+ *  <li>When an object is restored, an appropriate class for an object might not
+ *    be available. It must be possible to skip an object in this case.</li>
+ *  <li>When an object is restored, the appropriate class for the object may be
+ *    different from the one when the object was originally saved. If so, the
+ *    new class should still be able to read the old form of the data.</li>
+ * </ol>
+ * </p>
+ * <p>
+ * 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.
+ * </p><p>
+ * The key for an attribute may be any alpha numeric value.  However, the
+ * value of <code>TAG_ID</code> is reserved for internal use.
+ * </p><p>
+ * This interface is not intended to be implemented by clients.
+ * </p>
+ *
+ * @see IPersistableElement
+ * @see IElementFactory
+ */
+public interface IMemento {
+       /**
+        * Special reserved key used to store the memento id
+        * (value <code>"org.eclipse.ui.id"</code>).
+        *
+        * @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.
+        * <p>
+        * The <code>getChild</code> and <code>getChildren</code> methods
+        * are used to retrieve children of a given fType.
+        * </p>
+        *
+        * @param fType the fType
+        * @return a new child memento
+        * @see #getChild
+        * @see #getChildren
+        */
+       public IMemento createChild(String type);
+
+       /**
+        * Creates a new child of this memento with the given fType and id.
+        * The id is stored in the child memento (using a special reserved
+        * key, <code>TAG_ID</code>) and can be retrieved using <code>getId</code>.
+        * <p>
+        * The <code>getChild</code> and <code>getChildren</code> methods
+        * are used to retrieve children of a given fType.
+        * </p>
+        *
+        * @param fType the fType
+        * @param id the child id
+        * @return a new child memento with the given fType and id
+        * @see #getId
+        */
+       public IMemento createChild(String type, String id);
+
+       /**
+        * Returns the first child with the given fType id.
+        *
+        * @param fType the fType id
+        * @return the first child with the given fType
+        */
+       public IMemento getChild(String type);
+
+       /**
+        * Returns all children with the given fType id.
+        *
+        * @param fType the fType id
+        * @return the list of children with the given fType
+        */
+       public IMemento[] getChildren(String type);
+
+       /**
+        * Returns the floating point value of the given key.
+        *
+        * @param key the key
+        * @return the value, or <code>null</code> 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 <code>null</code> if none
+        * @see #createChild(java.lang.String,java.lang.String)
+        */
+       public String getId();
+
+       /**
+        * Returns the name for this memento.
+        *
+        * @return the memento name, or <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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  <code>memento</code>
+        * 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 (file)
index 0000000..dc1954d
--- /dev/null
@@ -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 (file)
index 0000000..023b508
--- /dev/null
@@ -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 (file)
index 0000000..0fd236f
--- /dev/null
@@ -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.
+        * <p>
+        * 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.
+        * </p>
+        *
+        * @param viewer
+        *          the viewer
+        * @param oldInput
+        *          the old input element, or <code>null</code> if the viewer did
+        *          not previously have an input
+        * @param newInput
+        *          the new input element, or <code>null</code> 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 (file)
index 0000000..68e2e22
--- /dev/null
@@ -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 (file)
index 0000000..ad23c6f
--- /dev/null
@@ -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.
+        * <p>
+        * 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 <code>super.performDefaults</code>.
+        * </p>
+        */
+       protected void performDefaults() {
+//             displayButton.setSelection(WikiEditorPlugin.getDefaultShowOnActivityPreference());
+               super.performDefaults();
+       }
+
+       /**
+        * Method declared on IPreferencePage.
+        * Subclasses should override
+        */
+       public boolean performOk() {
+//       WikiEditorPlugin.setShowOnActivityPreference(displayButton.getSelection());
+               PHPHelpPlugin.getDefault().savePluginPreferences();
+               return true;
+       }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencesDialog.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationPreferencesDialog.java
new file mode 100644 (file)
index 0000000..98682f7
--- /dev/null
@@ -0,0 +1,75 @@
+/**********************************************************************
+ * 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.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.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.Shell;
+
+public class ConfigurationPreferencesDialog extends Dialog {
+  protected IConfigurationWorkingCopy monitor;
+
+  protected boolean isEdit;
+
+  /**
+   * @param parentShell
+   */
+  public ConfigurationPreferencesDialog(Shell parentShell, IConfigurationWorkingCopy monitor) {
+    super(parentShell);
+    this.monitor = monitor;
+    isEdit = true;
+  }
+
+  public ConfigurationPreferencesDialog(Shell composite) {
+    super(composite);
+    isEdit = false;
+  }
+
+  protected void configureShell(Shell shell) {
+    super.configureShell(shell);
+    shell.setText(PHPHelpPlugin.getResource("%preferenceTitle"));
+  }
+
+  protected Control createDialogArea(Composite parent) {
+    Composite compositeParent = (Composite) super.createDialogArea(parent);
+
+    Composite composite = new Composite(compositeParent, SWT.NONE);
+    GridLayout layout = new GridLayout();
+    layout.marginHeight = convertHorizontalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+    layout.marginWidth = convertVerticalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+    composite.setLayout(layout);
+    GridData data = new GridData(GridData.FILL_BOTH);
+    composite.setLayoutData(data);
+    //         WorkbenchHelp.setHelp(composite, ContextIds.PREF);
+
+    ConfigurationComposite monitorComp = new ConfigurationComposite(composite, SWT.NONE);
+    data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+    monitorComp.setLayoutData(data);
+
+    Dialog.applyDialogFont(composite);
+
+    return composite;
+  }
+
+  protected void okPressed() {
+       PHPHelpPlugin.getDefault().savePluginPreferences();
+    super.okPressed();
+  }
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationTableLabelProvider.java b/net.sourceforge.phpeclipse.phphelp/src/net/sourceforge/phpdt/httpquery/preferences/ConfigurationTableLabelProvider.java
new file mode 100644 (file)
index 0000000..c050d71
--- /dev/null
@@ -0,0 +1,115 @@
+/**********************************************************************
+ * 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.httpquery.config.IConfiguration;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Configuration table label provider.
+ */
+public class ConfigurationTableLabelProvider implements ITableLabelProvider {
+  /**
+   * ConfigurationTableLabelProvider constructor comment.
+   */
+  public ConfigurationTableLabelProvider() {
+    super();
+  }
+
+  /**
+   * Adds a listener to this label provider. Has no effect if an identical listener is already registered.
+   * <p>
+   * Label provider listeners are informed about state changes that affect the rendering of the viewer that uses this label
+   * provider.
+   * </p>
+   *
+   * @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, or <code>null</code> 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 <code>null</code> 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 <code>true</code> if the label would be affected, and <code>false</code> 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 (file)
index 0000000..2701b21
--- /dev/null
@@ -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;
+       }
+}
index f296936..3c24502 100644 (file)
  **********************************************************************/
 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+                       + "<configurations>"
+                       + "<config name=\"PHP Online Manual\" type-id=\"HTTP Query\" url=\"http://www.php.net/manual/en/function.$php.selection.php\"/>"
+                       + "<config name=\"Google Search\" type-id=\"HTTP Query\" url=\"http://www.google.com/search?q=$text.selection\"/>"
+                       + "<config name=\"Koders.com Search\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>"
+                       + "<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
+                       + "</configurations>";
+
+       public static final ArrayList CONFIGURATION_TYPES = new ArrayList();
+
        /**
         * The id of the PHP plugin (value
         * <code>"net.sourceforge.phpeclipse.phphelp"</code>).
@@ -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