1.0.4 release
authorkhartlage <khartlage>
Sun, 5 Jan 2003 10:05:37 +0000 (10:05 +0000)
committerkhartlage <khartlage>
Sun, 5 Jan 2003 10:05:37 +0000 (10:05 +0000)
12 files changed:
net.sourceforge.phpeclipse/build.xml
net.sourceforge.phpeclipse/icons/obj16/htmledit.gif [new file with mode: 0644]
net.sourceforge.phpeclipse/icons/obj16/xmledit.gif [new file with mode: 0644]
net.sourceforge.phpeclipse/plugin.properties
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/default-templates.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/TemplatePreferencePage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorEnvironment.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCompletionProcessor.java [new file with mode: 0644]

index 56c4566..a71d691 100644 (file)
@@ -8,7 +8,7 @@
 
        <target name="init" depends="properties">
                <property name="plugin" value="net.sourceforge.phpeclipse"/>
-               <property name="version.suffix" value="_1.0.3"/>
+               <property name="version.suffix" value="_1.0.4"/>
                <property name="full.name" value="${plugin}${version.suffix}"/>
                <property name="temp.folder" value="${basedir}/temp.folder"/>
                <property name="plugin.destination" value="${basedir}"/>
diff --git a/net.sourceforge.phpeclipse/icons/obj16/htmledit.gif b/net.sourceforge.phpeclipse/icons/obj16/htmledit.gif
new file mode 100644 (file)
index 0000000..06dfa7a
Binary files /dev/null and b/net.sourceforge.phpeclipse/icons/obj16/htmledit.gif differ
diff --git a/net.sourceforge.phpeclipse/icons/obj16/xmledit.gif b/net.sourceforge.phpeclipse/icons/obj16/xmledit.gif
new file mode 100644 (file)
index 0000000..c5d5e95
Binary files /dev/null and b/net.sourceforge.phpeclipse/icons/obj16/xmledit.gif differ
index 19fe179..66559cb 100644 (file)
@@ -30,6 +30,6 @@ phtmlFileExtension=phtml
 #
 
 php.menu.label=&Source
-phpActionSet.label=Source Actions
+phpActionSet.label=PHP Source Actions
 phpUncommentAction.label=&Uncomment@Ctrl+\\
 phpCommentAction.label=&Comment@Ctrl+/
\ No newline at end of file
index dd10e7d..63b226c 100644 (file)
             type="text"
             extension="htm">
       </fileTypes>
+      <fileTypes
+            type="text"
+            extension="xml">
+      </fileTypes>
    </extension>
    <extension
          point="org.eclipse.ui.perspectives">
                id="net.sourceforge.phpeclipse.actions.PHPStartMySQLAction">
          </action>
       </actionSet>
+  <!--    <actionSet
+               id="net.sourceforge.phpeclipse.ui.CodingActionSet"
+        label="%phpActionSet.label"
+               visible="false"
+               description="%CodingActionSet.description">
+               <menu
+            id="net.sourceforge.phpeclipse.ui.source.menu"
+            label="%php.menu.label"
+            path="edit">
+               <separator name="editGroup"/>
+       </menu>
+       <action id="net.sourceforge.phpeclipse.ui.actions.Uncomment"
+               menubarPath="net.sourceforge.phpeclipse.ui.source.menu/editGroup"
+               label="%phpUncommentAction.label"
+                       retarget="true" />
+                       
+               <action id="net.sourceforge.phpeclipse.ui.actions.Comment"
+               menubarPath="net.sourceforge.phpeclipse.ui.source.menu/editGroup"
+               label="%phpCommentAction.label"
+                       retarget="true" />
+         </actionSet> -->
    </extension>
-<!--  <extension
+  <!-- <extension
          point="org.eclipse.ui.actionDefinitions">
       <actionDefinition
             id="net.sourceforge.phpeclipse.phpeditor.comment">
       </editor>
       <editor
             name="%phpEditorName"
-            icon="icons/obj16/phpedit.gif"
+            icon="icons/obj16/htmledit.gif"
             extensions="htm"
             contributorClass="net.sourceforge.phpeclipse.phpeditor.PHPActionContributor"
             class="net.sourceforge.phpeclipse.phpeditor.PHPEditor"
       </editor>
       <editor
             name="%phpEditorName"
-            icon="icons/obj16/phpedit.gif"
+            icon="icons/obj16/htmledit.gif"
             extensions="html"
             contributorClass="net.sourceforge.phpeclipse.phpeditor.PHPActionContributor"
             class="net.sourceforge.phpeclipse.phpeditor.PHPEditor"
             id="net.sourceforge.phpeclipse.PHPEditor">
       </editor>
+      <editor
+            name="%phpEditorName"
+            icon="icons/obj16/xmledit.gif"
+            extensions="xml"
+            contributorClass="net.sourceforge.phpeclipse.phpeditor.PHPActionContributor"
+            class="net.sourceforge.phpeclipse.phpeditor.PHPEditor"
+            id="net.sourceforge.phpeclipse.PHPEditor">
+      </editor>
    </extension>
    <extension
          point="org.eclipse.ui.popupMenus">
          point="org.eclipse.ui.views">
       <view
             name="%phpConsoleView"
-            icon="icons/obj16/java.gif"
+            icon="icons/obj16/php.gif"
             class="net.sourceforge.phpeclipse.views.PHPConsole"
             id="net.sourceforge.phpeclipse.views.phpconsoleview">
       </view>
index 4f29b3a..5be15b7 100644 (file)
   <template name="&lt;blockquote" description="blockquoted text" context="html" enabled="true">
   &lt;blockquote&gt;${cursor}&lt;/blockquote&gt;
   </template>
-  
+  <template name="&lt;xml" description="xml version=1.0" context="html" enabled="true">
+  &lt;?xml version="1.0"?&gt;
+  ${cursor}
+  </template>
+  <template name="&lt;xml" description="xml-stylesheet type=text/xsl" context="html" enabled="true">
+  &lt;?xml-stylesheet type="text/xsl" href="${url}"&gt;
+  ${cursor}
+  </template>
+
   <template name="&amp;quot" description="quot" context="html" enabled="true">&amp;quot;</template>
   <template name="&amp;amp" description="ampersand" context="html" enabled="true">&amp;amp;</template>
   <template name="&amp;lt" description="less than" context="html" enabled="true">&amp;lt;</template>
index 1424d1f..b90c52c 100644 (file)
@@ -15,8 +15,8 @@ import net.sourceforge.phpdt.internal.ui.text.template.TemplateContentProvider;
 import net.sourceforge.phpdt.internal.ui.text.template.TemplateLabelProvider;
 import net.sourceforge.phpdt.internal.ui.util.SWTUtil;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPEditorEnvironment;
 import net.sourceforge.phpeclipse.phpeditor.PHPSourceViewerConfiguration;
-import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -25,7 +25,6 @@ import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.text.Document;
 import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
 import org.eclipse.jface.text.source.SourceViewer;
 import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
@@ -61,566 +60,571 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
 
 public class TemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
 
-       // preference store keys
-       private static final String PREF_FORMAT_TEMPLATES= PHPeclipsePlugin.PLUGIN_ID + ".template.format"; //$NON-NLS-1$
-
-       private Templates fTemplates;
-
-       private CheckboxTableViewer fTableViewer;
-       private Button fAddButton;
-       private Button fEditButton;
-       private Button fImportButton;
-       private Button fExportButton;
-       private Button fExportAllButton;
-       private Button fRemoveButton;
-       private Button fEnableAllButton;
-       private Button fDisableAllButton;
-
-       private SourceViewer fPatternViewer;
-//     private Button fFormatButton;
-       
-       public TemplatePreferencePage() {
-               super();
-               
-               setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
-               setDescription(TemplateMessages.getString("TemplatePreferencePage.message")); //$NON-NLS-1$
-
-               fTemplates= Templates.getInstance();
-       }
-
-       /*
-        * @see PreferencePage#createContents(Composite)
-        */
-       protected Control createContents(Composite ancestor) {  
-               Composite parent= new Composite(ancestor, SWT.NONE);
-               GridLayout layout= new GridLayout();
-               layout.numColumns= 2;
-               layout.marginHeight= 0;
-               layout.marginWidth= 0;
-               parent.setLayout(layout);                               
-
-        Composite innerParent= new Composite(parent, SWT.NONE);
-        GridLayout innerLayout= new GridLayout();
-        innerLayout.numColumns= 2;
-        innerLayout.marginHeight= 0;
-        innerLayout.marginWidth= 0;
-        innerParent.setLayout(innerLayout);
-        GridData gd= new GridData(GridData.FILL_BOTH);
-        gd.horizontalSpan= 2;
-        innerParent.setLayoutData(gd);
-
-               Table table= new Table(innerParent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
-               
-               GridData data= new GridData(GridData.FILL_BOTH);
-               data.widthHint= convertWidthInCharsToPixels(3);
-               data.heightHint= convertHeightInCharsToPixels(10);
-               table.setLayoutData(data);
-                               
-               table.setHeaderVisible(true);
-               table.setLinesVisible(true);            
-
-               TableLayout tableLayout= new TableLayout();
-               table.setLayout(tableLayout);
-
-               TableColumn column1= new TableColumn(table, SWT.NONE);          
-               column1.setText(TemplateMessages.getString("TemplatePreferencePage.column.name")); //$NON-NLS-1$
-
-               TableColumn column2= new TableColumn(table, SWT.NONE);
-               column2.setText(TemplateMessages.getString("TemplatePreferencePage.column.context")); //$NON-NLS-1$
-       
-               TableColumn column3= new TableColumn(table, SWT.NONE);
-               column3.setText(TemplateMessages.getString("TemplatePreferencePage.column.description")); //$NON-NLS-1$
-               
-               fTableViewer= new CheckboxTableViewer(table);           
-               fTableViewer.setLabelProvider(new TemplateLabelProvider());
-               fTableViewer.setContentProvider(new TemplateContentProvider());
-
-               fTableViewer.setSorter(new ViewerSorter() {
-                       public int compare(Viewer viewer, Object object1, Object object2) {
-                               if ((object1 instanceof Template) && (object2 instanceof Template)) {
-                                       Template left= (Template) object1;
-                                       Template right= (Template) object2;
-                                       int result= left.getName().compareToIgnoreCase(right.getName());
-                                       if (result != 0)
-                                               return result;
-                                       return left.getDescription().compareToIgnoreCase(right.getDescription());
-                               }
-                               return super.compare(viewer, object1, object2);
-                       }
-                       
-                       public boolean isSorterProperty(Object element, String property) {
-                               return true;
-                       }
-               });
-               
-               fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
-                       public void doubleClick(DoubleClickEvent e) {
-                               edit();
-                       }
-               });
-               
-               fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-                       public void selectionChanged(SelectionChangedEvent e) {
-                               selectionChanged1();
-                       }
-               });
-
-               fTableViewer.addCheckStateListener(new ICheckStateListener() {
-                       public void checkStateChanged(CheckStateChangedEvent event) {
-                               Template template= (Template) event.getElement();
-                               template.setEnabled(event.getChecked());
-                       }
-               });
-
-               Composite buttons= new Composite(innerParent, SWT.NONE);
-               buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
-               layout= new GridLayout();
-               layout.marginHeight= 0;
-               layout.marginWidth= 0;
-               buttons.setLayout(layout);
-               
-               fAddButton= new Button(buttons, SWT.PUSH);
-               fAddButton.setText(TemplateMessages.getString("TemplatePreferencePage.new")); //$NON-NLS-1$
-               fAddButton.setLayoutData(getButtonGridData(fAddButton));
-               fAddButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               add();
-                       }
-               });
-
-               fEditButton= new Button(buttons, SWT.PUSH);
-               fEditButton.setText(TemplateMessages.getString("TemplatePreferencePage.edit")); //$NON-NLS-1$
-               fEditButton.setLayoutData(getButtonGridData(fEditButton));
-               fEditButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               edit();
-                       }
-               });
-
-               fRemoveButton= new Button(buttons, SWT.PUSH);
-               fRemoveButton.setText(TemplateMessages.getString("TemplatePreferencePage.remove")); //$NON-NLS-1$
-               fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
-               fRemoveButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               remove();
-                       }
-               });
-                               
-               fImportButton= new Button(buttons, SWT.PUSH);
-               fImportButton.setText(TemplateMessages.getString("TemplatePreferencePage.import")); //$NON-NLS-1$
-               fImportButton.setLayoutData(getButtonGridData(fImportButton));
-               fImportButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               import_();
-                       }
-               });
-
-               fExportButton= new Button(buttons, SWT.PUSH);
-               fExportButton.setText(TemplateMessages.getString("TemplatePreferencePage.export")); //$NON-NLS-1$
-               fExportButton.setLayoutData(getButtonGridData(fExportButton));
-               fExportButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               export();
-                       }
-               });
-
-               fExportAllButton= new Button(buttons, SWT.PUSH);
-               fExportAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.export.all")); //$NON-NLS-1$
-               fExportAllButton.setLayoutData(getButtonGridData(fExportAllButton));
-               fExportAllButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               exportAll();
-                       }
-               });             
-
-               fEnableAllButton= new Button(buttons, SWT.PUSH);
-               fEnableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.enable.all")); //$NON-NLS-1$
-               fEnableAllButton.setLayoutData(getButtonGridData(fEnableAllButton));
-               fEnableAllButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               enableAll(true);
-                       }
-               });
-
-               fDisableAllButton= new Button(buttons, SWT.PUSH);
-               fDisableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.disable.all")); //$NON-NLS-1$
-               fDisableAllButton.setLayoutData(getButtonGridData(fDisableAllButton));
-               fDisableAllButton.addListener(SWT.Selection, new Listener() {
-                       public void handleEvent(Event e) {
-                               enableAll(false);
-                       }
-               });
-
-               fPatternViewer= createViewer(parent);
-               
-//             fFormatButton= new Button(parent, SWT.CHECK);
-//             fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$
-//        GridData gd1= new GridData();
-//        gd1.horizontalSpan= 2;
-//        fFormatButton.setLayoutData(gd1);
-
-               fTableViewer.setInput(fTemplates);              
-               fTableViewer.setAllChecked(false);
-               fTableViewer.setCheckedElements(getEnabledTemplates());         
-
-               IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
-       //      fFormatButton.setSelection(prefs.getBoolean(PREF_FORMAT_TEMPLATES));
-
-               updateButtons();
-        configureTableResizing(innerParent, buttons, table, column1, column2, column3);
-
-               // WorkbenchHelp.setHelp(parent, IJavaHelpContextIds.TEMPLATE_PREFERENCE_PAGE);
-               
-               return parent;
-       }
-    
-     /**
-     * Correctly resizes the table so no phantom columns appear
-     */
-    private static void configureTableResizing(final Composite parent, final Composite buttons, final Table table, final TableColumn column1, final TableColumn column2, final TableColumn column3) {
-        parent.addControlListener(new ControlAdapter() {
-            public void controlResized(ControlEvent e) {
-                Rectangle area = parent.getClientArea();
-                Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-                int width = area.width - 2 * table.getBorderWidth();
-                if (preferredSize.y > area.height) {
-                    // Subtract the scrollbar width from the total column width
-                    // if a vertical scrollbar will be required
-                    Point vBarSize = table.getVerticalBar().getSize();
-                    width -= vBarSize.x;
-                }
-                width-= buttons.getSize().x;
-                Point oldSize = table.getSize();
-                if (oldSize.x > width) {
-                    // table is getting smaller so make the columns
-                    // smaller first and then resize the table to
-                    // match the client area width
-                    column1.setWidth(width/4);
-                    column2.setWidth(width/4);
-                    column3.setWidth(width - (column1.getWidth() + column2.getWidth()));
-                    table.setSize(width, area.height);
-                } else {
-                    // table is getting bigger so make the table
-                    // bigger first and then make the columns wider
-                    // to match the client area width
-                    table.setSize(width, area.height);
-                    column1.setWidth(width/4);
-                    column2.setWidth(width/4);
-                    column3.setWidth(width - (column1.getWidth() + column2.getWidth()));
-                 }
-            }
-        });
+  // preference store keys
+  private static final String PREF_FORMAT_TEMPLATES = PHPeclipsePlugin.PLUGIN_ID + ".template.format"; //$NON-NLS-1$
+
+  private Templates fTemplates;
+
+  private CheckboxTableViewer fTableViewer;
+  private Button fAddButton;
+  private Button fEditButton;
+  private Button fImportButton;
+  private Button fExportButton;
+  private Button fExportAllButton;
+  private Button fRemoveButton;
+  private Button fEnableAllButton;
+  private Button fDisableAllButton;
+
+  private SourceViewer fPatternViewer;
+  //   private Button fFormatButton;
+
+  public TemplatePreferencePage() {
+    super();
+
+    setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
+    setDescription(TemplateMessages.getString("TemplatePreferencePage.message")); //$NON-NLS-1$
+
+    fTemplates = Templates.getInstance();
+  }
+
+  /*
+   * @see PreferencePage#createContents(Composite)
+   */
+  protected Control createContents(Composite ancestor) {
+    PHPEditorEnvironment.connect(this);
+    Composite parent = new Composite(ancestor, SWT.NONE);
+    GridLayout layout = new GridLayout();
+    layout.numColumns = 2;
+    layout.marginHeight = 0;
+    layout.marginWidth = 0;
+    parent.setLayout(layout);
+
+    Composite innerParent = new Composite(parent, SWT.NONE);
+    GridLayout innerLayout = new GridLayout();
+    innerLayout.numColumns = 2;
+    innerLayout.marginHeight = 0;
+    innerLayout.marginWidth = 0;
+    innerParent.setLayout(innerLayout);
+    GridData gd = new GridData(GridData.FILL_BOTH);
+    gd.horizontalSpan = 2;
+    innerParent.setLayoutData(gd);
+
+    Table table = new Table(innerParent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+
+    GridData data = new GridData(GridData.FILL_BOTH);
+    data.widthHint = convertWidthInCharsToPixels(3);
+    data.heightHint = convertHeightInCharsToPixels(10);
+    table.setLayoutData(data);
+
+    table.setHeaderVisible(true);
+    table.setLinesVisible(true);
+
+    TableLayout tableLayout = new TableLayout();
+    table.setLayout(tableLayout);
+
+    TableColumn column1 = new TableColumn(table, SWT.NONE);
+    column1.setText(TemplateMessages.getString("TemplatePreferencePage.column.name")); //$NON-NLS-1$
+
+    TableColumn column2 = new TableColumn(table, SWT.NONE);
+    column2.setText(TemplateMessages.getString("TemplatePreferencePage.column.context")); //$NON-NLS-1$
+
+    TableColumn column3 = new TableColumn(table, SWT.NONE);
+    column3.setText(TemplateMessages.getString("TemplatePreferencePage.column.description")); //$NON-NLS-1$
+
+    fTableViewer = new CheckboxTableViewer(table);
+    fTableViewer.setLabelProvider(new TemplateLabelProvider());
+    fTableViewer.setContentProvider(new TemplateContentProvider());
+
+    fTableViewer.setSorter(new ViewerSorter() {
+      public int compare(Viewer viewer, Object object1, Object object2) {
+        if ((object1 instanceof Template) && (object2 instanceof Template)) {
+          Template left = (Template) object1;
+          Template right = (Template) object2;
+          int result = left.getName().compareToIgnoreCase(right.getName());
+          if (result != 0)
+            return result;
+          return left.getDescription().compareToIgnoreCase(right.getDescription());
+        }
+        return super.compare(viewer, object1, object2);
+      }
+
+      public boolean isSorterProperty(Object element, String property) {
+        return true;
+      }
+    });
+
+    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
+      public void doubleClick(DoubleClickEvent e) {
+        edit();
+      }
+    });
+
+    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+      public void selectionChanged(SelectionChangedEvent e) {
+        selectionChanged1();
+      }
+    });
+
+    fTableViewer.addCheckStateListener(new ICheckStateListener() {
+      public void checkStateChanged(CheckStateChangedEvent event) {
+        Template template = (Template) event.getElement();
+        template.setEnabled(event.getChecked());
+      }
+    });
+
+    Composite buttons = new Composite(innerParent, SWT.NONE);
+    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+    layout = new GridLayout();
+    layout.marginHeight = 0;
+    layout.marginWidth = 0;
+    buttons.setLayout(layout);
+
+    fAddButton = new Button(buttons, SWT.PUSH);
+    fAddButton.setText(TemplateMessages.getString("TemplatePreferencePage.new")); //$NON-NLS-1$
+    fAddButton.setLayoutData(getButtonGridData(fAddButton));
+    fAddButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        add();
+      }
+    });
+
+    fEditButton = new Button(buttons, SWT.PUSH);
+    fEditButton.setText(TemplateMessages.getString("TemplatePreferencePage.edit")); //$NON-NLS-1$
+    fEditButton.setLayoutData(getButtonGridData(fEditButton));
+    fEditButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        edit();
+      }
+    });
+
+    fRemoveButton = new Button(buttons, SWT.PUSH);
+    fRemoveButton.setText(TemplateMessages.getString("TemplatePreferencePage.remove")); //$NON-NLS-1$
+    fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
+    fRemoveButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        remove();
+      }
+    });
+
+    fImportButton = new Button(buttons, SWT.PUSH);
+    fImportButton.setText(TemplateMessages.getString("TemplatePreferencePage.import")); //$NON-NLS-1$
+    fImportButton.setLayoutData(getButtonGridData(fImportButton));
+    fImportButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        import_();
+      }
+    });
+
+    fExportButton = new Button(buttons, SWT.PUSH);
+    fExportButton.setText(TemplateMessages.getString("TemplatePreferencePage.export")); //$NON-NLS-1$
+    fExportButton.setLayoutData(getButtonGridData(fExportButton));
+    fExportButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        export();
+      }
+    });
+
+    fExportAllButton = new Button(buttons, SWT.PUSH);
+    fExportAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.export.all")); //$NON-NLS-1$
+    fExportAllButton.setLayoutData(getButtonGridData(fExportAllButton));
+    fExportAllButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        exportAll();
+      }
+    });
+
+    fEnableAllButton = new Button(buttons, SWT.PUSH);
+    fEnableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.enable.all")); //$NON-NLS-1$
+    fEnableAllButton.setLayoutData(getButtonGridData(fEnableAllButton));
+    fEnableAllButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        enableAll(true);
+      }
+    });
+
+    fDisableAllButton = new Button(buttons, SWT.PUSH);
+    fDisableAllButton.setText(TemplateMessages.getString("TemplatePreferencePage.disable.all")); //$NON-NLS-1$
+    fDisableAllButton.setLayoutData(getButtonGridData(fDisableAllButton));
+    fDisableAllButton.addListener(SWT.Selection, new Listener() {
+      public void handleEvent(Event e) {
+        enableAll(false);
+      }
+    });
+
+    fPatternViewer = createViewer(parent);
+
+    //         fFormatButton= new Button(parent, SWT.CHECK);
+    //         fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$
+    //        GridData gd1= new GridData();
+    //        gd1.horizontalSpan= 2;
+    //        fFormatButton.setLayoutData(gd1);
+
+    fTableViewer.setInput(fTemplates);
+    fTableViewer.setAllChecked(false);
+    fTableViewer.setCheckedElements(getEnabledTemplates());
+
+    IPreferenceStore prefs = PHPeclipsePlugin.getDefault().getPreferenceStore();
+    // fFormatButton.setSelection(prefs.getBoolean(PREF_FORMAT_TEMPLATES));
+
+    updateButtons();
+    configureTableResizing(innerParent, buttons, table, column1, column2, column3);
+
+    // WorkbenchHelp.setHelp(parent, IJavaHelpContextIds.TEMPLATE_PREFERENCE_PAGE);
+
+    return parent;
+  }
+
+  /**
+  * Correctly resizes the table so no phantom columns appear
+  */
+  private static void configureTableResizing(
+    final Composite parent,
+    final Composite buttons,
+    final Table table,
+    final TableColumn column1,
+    final TableColumn column2,
+    final TableColumn column3) {
+    parent.addControlListener(new ControlAdapter() {
+      public void controlResized(ControlEvent e) {
+        Rectangle area = parent.getClientArea();
+        Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+        int width = area.width - 2 * table.getBorderWidth();
+        if (preferredSize.y > area.height) {
+          // Subtract the scrollbar width from the total column width
+          // if a vertical scrollbar will be required
+          Point vBarSize = table.getVerticalBar().getSize();
+          width -= vBarSize.x;
+        }
+        width -= buttons.getSize().x;
+        Point oldSize = table.getSize();
+        if (oldSize.x > width) {
+          // table is getting smaller so make the columns
+          // smaller first and then resize the table to
+          // match the client area width
+          column1.setWidth(width / 4);
+          column2.setWidth(width / 4);
+          column3.setWidth(width - (column1.getWidth() + column2.getWidth()));
+          table.setSize(width, area.height);
+        } else {
+          // table is getting bigger so make the table
+          // bigger first and then make the columns wider
+          // to match the client area width
+          table.setSize(width, area.height);
+          column1.setWidth(width / 4);
+          column2.setWidth(width / 4);
+          column3.setWidth(width - (column1.getWidth() + column2.getWidth()));
+        }
+      }
+    });
+  }
+
+  private Template[] getEnabledTemplates() {
+    Template[] templates = fTemplates.getTemplates();
+
+    List list = new ArrayList(templates.length);
+
+    for (int i = 0; i != templates.length; i++)
+      if (templates[i].isEnabled())
+        list.add(templates[i]);
+
+    return (Template[]) list.toArray(new Template[list.size()]);
+  }
+
+  private SourceViewer createViewer(Composite parent) {
+    Label label = new Label(parent, SWT.NONE);
+    label.setText(TemplateMessages.getString("TemplatePreferencePage.preview")); //$NON-NLS-1$
+    GridData data = new GridData();
+    data.horizontalSpan = 2;
+    label.setLayoutData(data);
+
+    SourceViewer viewer = new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+    //         JavaTextTools tools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+    IDocument document = new Document();
+    //         IDocumentPartitioner partitioner= new PHPPartitionScanner(); //tools.createDocumentPartitioner();
+    //         document.setDocumentPartitioner(partitioner);
+    //         partitioner.connect(document);          
+
+    viewer.configure(new PHPSourceViewerConfiguration()); // (tools, null));
+    viewer.setEditable(false);
+    viewer.setDocument(document);
+    viewer.getTextWidget().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+
+    Font font = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
+    viewer.getTextWidget().setFont(font);
+
+    Control control = viewer.getControl();
+    data = new GridData(GridData.FILL_BOTH);
+    data.horizontalSpan = 2;
+    data.heightHint = convertHeightInCharsToPixels(5);
+    control.setLayoutData(data);
+
+    return viewer;
+  }
+
+  private static GridData getButtonGridData(Button button) {
+    GridData data = new GridData(GridData.FILL_HORIZONTAL);
+    data.widthHint = SWTUtil.getButtonWidthHint(button);
+    data.heightHint = SWTUtil.getButtonHeigthHint(button);
+
+    return data;
+  }
+
+  private void selectionChanged1() {
+    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
+
+    if (selection.size() == 1) {
+      Template template = (Template) selection.getFirstElement();
+      fPatternViewer.getTextWidget().setText(template.getPattern());
+    } else {
+      fPatternViewer.getTextWidget().setText(""); //$NON-NLS-1$
     }
-    
-       
-       private Template[] getEnabledTemplates() {
-               Template[] templates= fTemplates.getTemplates();
-               
-               List list= new ArrayList(templates.length);
-               
-               for (int i= 0; i != templates.length; i++)
-                       if (templates[i].isEnabled())
-                               list.add(templates[i]);
-                               
-               return (Template[]) list.toArray(new Template[list.size()]);
-       }
-       
-       private SourceViewer createViewer(Composite parent) {
-               Label label= new Label(parent, SWT.NONE);
-               label.setText(TemplateMessages.getString("TemplatePreferencePage.preview")); //$NON-NLS-1$
-               GridData data= new GridData();
-               data.horizontalSpan= 2;
-               label.setLayoutData(data);
-               
-               SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
-//             JavaTextTools tools= PHPeclipsePlugin.getDefault().getJavaTextTools();
-               IDocument document= new Document();
-//             IDocumentPartitioner partitioner= new PHPPartitionScanner(); //tools.createDocumentPartitioner();
-//             document.setDocumentPartitioner(partitioner);
-//             partitioner.connect(document);          
-               viewer.configure(new PHPSourceViewerConfiguration()); // (tools, null));
-               viewer.setEditable(false);
-               viewer.setDocument(document);
-               viewer.getTextWidget().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
-       
-               Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
-               viewer.getTextWidget().setFont(font);
-               
-               Control control= viewer.getControl();
-               data= new GridData(GridData.FILL_BOTH);
-        data.horizontalSpan= 2;
-               data.heightHint= convertHeightInCharsToPixels(5);
-               control.setLayoutData(data);
-               
-               return viewer;
-       }
-       
-       private static GridData getButtonGridData(Button button) {
-               GridData data= new GridData(GridData.FILL_HORIZONTAL);
-               data.widthHint= SWTUtil.getButtonWidthHint(button);
-               data.heightHint= SWTUtil.getButtonHeigthHint(button);
-       
-               return data;
-       }
-       
-       private void selectionChanged1() {              
-               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
-
-               if (selection.size() == 1) {
-                       Template template= (Template) selection.getFirstElement();
-                       fPatternViewer.getTextWidget().setText(template.getPattern());
-               } else {                
-                       fPatternViewer.getTextWidget().setText(""); //$NON-NLS-1$
-               }
-               
-               updateButtons();
-       }
-       
-       private void updateButtons() {
-               int selectionCount= ((IStructuredSelection) fTableViewer.getSelection()).size();
-               int itemCount= fTableViewer.getTable().getItemCount();
-               
-               fEditButton.setEnabled(selectionCount == 1);
-               fExportButton.setEnabled(selectionCount > 0);
-               fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount);
-               fEnableAllButton.setEnabled(itemCount > 0);
-               fDisableAllButton.setEnabled(itemCount > 0);
-       }
-       
-       private void add() {            
-               
-               Template template= new Template();
-
-               ContextTypeRegistry registry=ContextTypeRegistry.getInstance();
-               ContextType type= registry.getContextType("php"); //$NON-NLS-1$
-               
-               String contextTypeName;
-               if (type != null)
-                       contextTypeName= type.getName();
-               else {
-                       Iterator iterator= registry.iterator();
-                       contextTypeName= (String) iterator.next();
-               }
-               template.setContext(contextTypeName); //$NON-NLS-1$
-               
-               EditTemplateDialog dialog= new EditTemplateDialog(getShell(), template, false);
-               if (dialog.open() == dialog.OK) {
-                       fTemplates.add(template);
-                       fTableViewer.refresh();
-                       fTableViewer.setChecked(template, template.isEnabled());
-                       fTableViewer.setSelection(new StructuredSelection(template));                   
-               }
-       }
-
-       private void edit() {
-               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
-
-               Object[] objects= selection.toArray();          
-               if ((objects == null) || (objects.length != 1))
-                       return;
-               
-               Template template= (Template) selection.getFirstElement();
-               edit(template);
-       }
-
-       private void edit(Template template) {
-               Template newTemplate= new Template(template);
-               EditTemplateDialog dialog= new EditTemplateDialog(getShell(), newTemplate, true);
-               if (dialog.open() == dialog.OK) {
-
-                       if (!newTemplate.getName().equals(template.getName()) &&
-                               MessageDialog.openQuestion(getShell(),
-                               TemplateMessages.getString("TemplatePreferencePage.question.create.new.title"), //$NON-NLS-1$
-                               TemplateMessages.getString("TemplatePreferencePage.question.create.new.message"))) //$NON-NLS-1$
-                       {
-                               template= newTemplate;
-                               fTemplates.add(template);
-                               fTableViewer.refresh();
-                       } else {
-                               template.setName(newTemplate.getName());
-                               template.setDescription(newTemplate.getDescription());
-                               template.setContext(newTemplate.getContextTypeName());
-                               template.setPattern(newTemplate.getPattern());
-                               fTableViewer.refresh(template);
-                       }
-                       fTableViewer.setChecked(template, template.isEnabled());
-                       fTableViewer.setSelection(new StructuredSelection(template));                   
-               }
-       }
-               
-       private void import_() {
-               FileDialog dialog= new FileDialog(getShell());
-               dialog.setText(TemplateMessages.getString("TemplatePreferencePage.import.title")); //$NON-NLS-1$
-               dialog.setFilterExtensions(new String[] {TemplateMessages.getString("TemplatePreferencePage.import.extension")}); //$NON-NLS-1$
-               String path= dialog.open();
-               
-               if (path == null)
-                       return;
-               
-               try {
-                       fTemplates.addFromFile(new File(path));
-                       
-                       fTableViewer.refresh();
-                       fTableViewer.setAllChecked(false);
-                       fTableViewer.setCheckedElements(getEnabledTemplates());
-
-               } catch (CoreException e) {                     
-                       openReadErrorDialog(e);
-               }
-       }
-       
-       private void exportAll() {
-               export(fTemplates);     
-       }
-
-       private void export() {
-               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
-               Object[] templates= selection.toArray();
-               
-               TemplateSet templateSet= new TemplateSet();
-               for (int i= 0; i != templates.length; i++)
-                       templateSet.add((Template) templates[i]);
-               
-               export(templateSet);
-       }
-       
-       private void export(TemplateSet templateSet) {
-               FileDialog dialog= new FileDialog(getShell(), SWT.SAVE);
-               dialog.setText(TemplateMessages.getFormattedString("TemplatePreferencePage.export.title", new Integer(templateSet.getTemplates().length))); //$NON-NLS-1$
-               dialog.setFilterExtensions(new String[] {TemplateMessages.getString("TemplatePreferencePage.export.extension")}); //$NON-NLS-1$
-               dialog.setFileName(TemplateMessages.getString("TemplatePreferencePage.export.filename")); //$NON-NLS-1$
-               String path= dialog.open();
-               
-               if (path == null)
-                       return;
-               
-               File file= new File(path);              
-
-               if (!file.exists() || confirmOverwrite(file)) {
-                       try {
-                               templateSet.saveToFile(file);                   
-                       } catch (CoreException e) {                     
-                               PHPeclipsePlugin.log(e);
-                               openWriteErrorDialog(e);
-                       }               
-               }
-       }
-
-       private boolean confirmOverwrite(File file) {
-               return MessageDialog.openQuestion(getShell(),
-                       TemplateMessages.getString("TemplatePreferencePage.export.exists.title"), //$NON-NLS-1$
-                       TemplateMessages.getFormattedString("TemplatePreferencePage.export.exists.message", file.getAbsolutePath())); //$NON-NLS-1$
-       }
-       
-       private void remove() {
-               IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection();
-
-               Iterator elements= selection.iterator();
-               while (elements.hasNext()) {
-                       Template template= (Template) elements.next();
-                       fTemplates.remove(template);
-               }
-
-               fTableViewer.refresh();
-       }
-       
-       private void enableAll(boolean enable) {
-               Template[] templates= fTemplates.getTemplates();
-               for (int i= 0; i != templates.length; i++)
-                       templates[i].setEnabled(enable);                
-                       
-               fTableViewer.setAllChecked(enable);
-       }
-       
-       /*
-        * @see IWorkbenchPreferencePage#init(IWorkbench)
-        */
-       public void init(IWorkbench workbench) {}
-
-       /*
-        * @see Control#setVisible(boolean)
-        */
-       public void setVisible(boolean visible) {
-               super.setVisible(visible);
-               if (visible)
-                       setTitle(TemplateMessages.getString("TemplatePreferencePage.title")); //$NON-NLS-1$
-       }
-       
-       /*
-        * @see PreferencePage#performDefaults()
-        */
-       protected void performDefaults() {
-               IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
-       //      fFormatButton.setSelection(prefs.getDefaultBoolean(PREF_FORMAT_TEMPLATES));
-
-               try {
-                       fTemplates.restoreDefaults();
-               } catch (CoreException e) {
-                       PHPeclipsePlugin.log(e);
-                       openReadErrorDialog(e);
-               }
-               
-               // refresh
-               fTableViewer.refresh();
-               fTableViewer.setAllChecked(false);
-               fTableViewer.setCheckedElements(getEnabledTemplates());         
-       }
-
-       /*
-        * @see PreferencePage#performOk()
-        */     
-       public boolean performOk() {
-               IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
-       //      prefs.setValue(PREF_FORMAT_TEMPLATES, fFormatButton.getSelection());
-
-               try {
-                       fTemplates.save();
-               } catch (CoreException e) {
-                       PHPeclipsePlugin.log(e);
-                       openWriteErrorDialog(e);
-               }
-               
-               PHPeclipsePlugin.getDefault().savePluginPreferences();
-               return super.performOk();
-       }       
-       
-       /*
-        * @see PreferencePage#performCancel()
-        */
-       public boolean performCancel() {
-               try {
-                       fTemplates.reset();                     
-               } catch (CoreException e) {
-                       PHPeclipsePlugin.log(e);
-                       openReadErrorDialog(e);
-               }
-
-               return super.performCancel();
-       }
-       
-       /**
-        * Initializes the default values of this page in the preference bundle.
-        * Will be called on startup of the PHPeclipsePlugin
-        */
-       public static void initDefaults(IPreferenceStore prefs) {
-               prefs.setDefault(PREF_FORMAT_TEMPLATES, true);
-       }
-
-//     public static boolean useCodeFormatter() {
-//             IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
-//             return prefs.getBoolean(PREF_FORMAT_TEMPLATES);
-//     }
-
-       private void openReadErrorDialog(CoreException e) {
-               ErrorDialog.openError(getShell(),
-                       TemplateMessages.getString("TemplatePreferencePage.error.read.title"), //$NON-NLS-1$
-                       null, e.getStatus());
-       }
-       
-       private void openWriteErrorDialog(CoreException e) {
-               ErrorDialog.openError(getShell(),
-                       TemplateMessages.getString("TemplatePreferencePage.error.write.title"), //$NON-NLS-1$
-                       null, e.getStatus());           
-       }
-               
+
+    updateButtons();
+  }
+
+  private void updateButtons() {
+    int selectionCount = ((IStructuredSelection) fTableViewer.getSelection()).size();
+    int itemCount = fTableViewer.getTable().getItemCount();
+
+    fEditButton.setEnabled(selectionCount == 1);
+    fExportButton.setEnabled(selectionCount > 0);
+    fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount);
+    fEnableAllButton.setEnabled(itemCount > 0);
+    fDisableAllButton.setEnabled(itemCount > 0);
+  }
+
+  private void add() {
+
+    Template template = new Template();
+
+    ContextTypeRegistry registry = ContextTypeRegistry.getInstance();
+    ContextType type = registry.getContextType("php"); //$NON-NLS-1$
+
+    String contextTypeName;
+    if (type != null)
+      contextTypeName = type.getName();
+    else {
+      Iterator iterator = registry.iterator();
+      contextTypeName = (String) iterator.next();
+    }
+    template.setContext(contextTypeName); //$NON-NLS-1$
+
+    EditTemplateDialog dialog = new EditTemplateDialog(getShell(), template, false);
+    if (dialog.open() == dialog.OK) {
+      fTemplates.add(template);
+      fTableViewer.refresh();
+      fTableViewer.setChecked(template, template.isEnabled());
+      fTableViewer.setSelection(new StructuredSelection(template));
+    }
+  }
+
+  private void edit() {
+    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
+
+    Object[] objects = selection.toArray();
+    if ((objects == null) || (objects.length != 1))
+      return;
+
+    Template template = (Template) selection.getFirstElement();
+    edit(template);
+  }
+
+  private void edit(Template template) {
+    Template newTemplate = new Template(template);
+    EditTemplateDialog dialog = new EditTemplateDialog(getShell(), newTemplate, true);
+    if (dialog.open() == dialog.OK) {
+
+      if (!newTemplate.getName().equals(template.getName()) && MessageDialog.openQuestion(getShell(), TemplateMessages.getString("TemplatePreferencePage.question.create.new.title"), //$NON-NLS-1$
+      TemplateMessages.getString("TemplatePreferencePage.question.create.new.message"))) //$NON-NLS-1$
+        {
+        template = newTemplate;
+        fTemplates.add(template);
+        fTableViewer.refresh();
+      } else {
+        template.setName(newTemplate.getName());
+        template.setDescription(newTemplate.getDescription());
+        template.setContext(newTemplate.getContextTypeName());
+        template.setPattern(newTemplate.getPattern());
+        fTableViewer.refresh(template);
+      }
+      fTableViewer.setChecked(template, template.isEnabled());
+      fTableViewer.setSelection(new StructuredSelection(template));
+    }
+  }
+
+  private void import_() {
+    FileDialog dialog = new FileDialog(getShell());
+    dialog.setText(TemplateMessages.getString("TemplatePreferencePage.import.title")); //$NON-NLS-1$
+    dialog.setFilterExtensions(new String[] { TemplateMessages.getString("TemplatePreferencePage.import.extension")}); //$NON-NLS-1$
+    String path = dialog.open();
+
+    if (path == null)
+      return;
+
+    try {
+      fTemplates.addFromFile(new File(path));
+
+      fTableViewer.refresh();
+      fTableViewer.setAllChecked(false);
+      fTableViewer.setCheckedElements(getEnabledTemplates());
+
+    } catch (CoreException e) {
+      openReadErrorDialog(e);
+    }
+  }
+
+  private void exportAll() {
+    export(fTemplates);
+  }
+
+  private void export() {
+    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
+    Object[] templates = selection.toArray();
+
+    TemplateSet templateSet = new TemplateSet();
+    for (int i = 0; i != templates.length; i++)
+      templateSet.add((Template) templates[i]);
+
+    export(templateSet);
+  }
+
+  private void export(TemplateSet templateSet) {
+    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
+    dialog.setText(TemplateMessages.getFormattedString("TemplatePreferencePage.export.title", new Integer(templateSet.getTemplates().length))); //$NON-NLS-1$
+    dialog.setFilterExtensions(new String[] { TemplateMessages.getString("TemplatePreferencePage.export.extension")}); //$NON-NLS-1$
+    dialog.setFileName(TemplateMessages.getString("TemplatePreferencePage.export.filename")); //$NON-NLS-1$
+    String path = dialog.open();
+
+    if (path == null)
+      return;
+
+    File file = new File(path);
+
+    if (!file.exists() || confirmOverwrite(file)) {
+      try {
+        templateSet.saveToFile(file);
+      } catch (CoreException e) {
+        PHPeclipsePlugin.log(e);
+        openWriteErrorDialog(e);
+      }
+    }
+  }
+
+  private boolean confirmOverwrite(File file) {
+    return MessageDialog.openQuestion(getShell(), TemplateMessages.getString("TemplatePreferencePage.export.exists.title"), //$NON-NLS-1$
+    TemplateMessages.getFormattedString("TemplatePreferencePage.export.exists.message", file.getAbsolutePath())); //$NON-NLS-1$
+  }
+
+  private void remove() {
+    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
+
+    Iterator elements = selection.iterator();
+    while (elements.hasNext()) {
+      Template template = (Template) elements.next();
+      fTemplates.remove(template);
+    }
+
+    fTableViewer.refresh();
+  }
+
+  private void enableAll(boolean enable) {
+    Template[] templates = fTemplates.getTemplates();
+    for (int i = 0; i != templates.length; i++)
+      templates[i].setEnabled(enable);
+
+    fTableViewer.setAllChecked(enable);
+  }
+
+  /*
+   * @see IWorkbenchPreferencePage#init(IWorkbench)
+   */
+  public void init(IWorkbench workbench) {
+  }
+
+  /*
+   * @see Control#setVisible(boolean)
+   */
+  public void setVisible(boolean visible) {
+    super.setVisible(visible);
+    if (visible)
+      setTitle(TemplateMessages.getString("TemplatePreferencePage.title")); //$NON-NLS-1$
+  }
+
+  /*
+   * @see PreferencePage#performDefaults()
+   */
+  protected void performDefaults() {
+    IPreferenceStore prefs = PHPeclipsePlugin.getDefault().getPreferenceStore();
+    // fFormatButton.setSelection(prefs.getDefaultBoolean(PREF_FORMAT_TEMPLATES));
+
+    try {
+      fTemplates.restoreDefaults();
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+      openReadErrorDialog(e);
+    }
+
+    // refresh
+    fTableViewer.refresh();
+    fTableViewer.setAllChecked(false);
+    fTableViewer.setCheckedElements(getEnabledTemplates());
+  }
+
+  /*
+   * @see PreferencePage#performOk()
+   */
+  public boolean performOk() {
+    IPreferenceStore prefs = PHPeclipsePlugin.getDefault().getPreferenceStore();
+    // prefs.setValue(PREF_FORMAT_TEMPLATES, fFormatButton.getSelection());
+
+    try {
+      fTemplates.save();
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+      openWriteErrorDialog(e);
+    }
+
+    PHPeclipsePlugin.getDefault().savePluginPreferences();
+    PHPEditorEnvironment.disconnect(this);
+    return super.performOk();
+  }
+
+  /*
+   * @see PreferencePage#performCancel()
+   */
+  public boolean performCancel() {
+    try {
+      fTemplates.reset();
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+      openReadErrorDialog(e);
+    }
+
+    PHPEditorEnvironment.disconnect(this);
+    return super.performCancel();
+  }
+
+  /**
+   * Initializes the default values of this page in the preference bundle.
+   * Will be called on startup of the PHPeclipsePlugin
+   */
+  public static void initDefaults(IPreferenceStore prefs) {
+    prefs.setDefault(PREF_FORMAT_TEMPLATES, true);
+  }
+
+  //   public static boolean useCodeFormatter() {
+  //           IPreferenceStore prefs= PHPeclipsePlugin.getDefault().getPreferenceStore();
+  //           return prefs.getBoolean(PREF_FORMAT_TEMPLATES);
+  //   }
+
+  private void openReadErrorDialog(CoreException e) {
+    ErrorDialog.openError(getShell(), TemplateMessages.getString("TemplatePreferencePage.error.read.title"), //$NON-NLS-1$
+    null, e.getStatus());
+  }
+
+  private void openWriteErrorDialog(CoreException e) {
+    ErrorDialog.openError(getShell(), TemplateMessages.getString("TemplatePreferencePage.error.write.title"), //$NON-NLS-1$
+    null, e.getStatus());
+  }
+
 }
index 71f26dc..2d0b71d 100644 (file)
@@ -18,8 +18,6 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.help.IHelp;
-import org.eclipse.help.IHelpResource;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.MenuManager;
@@ -28,7 +26,6 @@ import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextOperationTarget;
-import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.text.source.AnnotationRulerColumn;
 import org.eclipse.jface.text.source.CompositeRuler;
 import org.eclipse.jface.text.source.ISourceViewer;
@@ -41,7 +38,6 @@ import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.help.WorkbenchHelp;
 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 import org.eclipse.ui.texteditor.TextOperationAction;
@@ -49,7 +45,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 /**
  * PHP specific text editor.
  */
-public class PHPEditor extends TextEditor {
+public class PHPEditor extends TextEditor  {
 
   protected PHPActionGroup actionGroup;
   /** The outline page */
@@ -103,11 +99,12 @@ public class PHPEditor extends TextEditor {
 
     markAsStateDependentAction("Comment", true); //$NON-NLS-1$
     markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
+    
   }
 
-  /** The <code>JavaEditor</code> implementation of this 
+  /** The <code>PHPEditor</code> implementation of this 
    * <code>AbstractTextEditor</code> method performs any extra 
-   * disposal actions required by the java editor.
+   * disposal actions required by the php editor.
    */
   public void dispose() {
     PHPEditorEnvironment.disconnect(this);
@@ -163,9 +160,9 @@ public class PHPEditor extends TextEditor {
       fOutlinePage.setInput(input);
   }
 
-  /** The <code>JavaEditor</code> implementation of this 
+  /** The <code>PHPEditor</code> implementation of this 
    * <code>AbstractTextEditor</code> method adds any 
-   * JavaEditor specific entries.
+   * PHPEditor specific entries.
    */
   public void editorContextMenuAboutToShow(MenuManager menu) {
     super.editorContextMenuAboutToShow(menu);
@@ -174,7 +171,7 @@ public class PHPEditor extends TextEditor {
     actionGroup.fillContextMenu(menu);
   }
 
-  /** The <code>JavaEditor</code> implementation of this 
+  /** The <code>PHPEditor</code> implementation of this 
    * <code>AbstractTextEditor</code> method performs gets
    * the java content outline page if request is for a an 
    * outline page.
index 011feb4..8ebe447 100644 (file)
@@ -23,7 +23,7 @@ import org.eclipse.jface.text.rules.RuleBasedScanner;
 public class PHPEditorEnvironment {
 
   private static PHPColorProvider fgColorProvider;
-  private static PHPCodeScanner fgCodeScanner;
+  private static PHPCodeScanner fgPHPCodeScanner;
   private static HTMLCodeScanner fgHTMLCodeScanner;
   //private static JavaDocScanner fgDocScanner;
 
@@ -35,7 +35,7 @@ public class PHPEditorEnvironment {
   public static void connect(Object client) {
     if (++fgRefCount == 1) {
       fgColorProvider = new PHPColorProvider();
-      fgCodeScanner = new PHPCodeScanner(fgColorProvider);
+      fgPHPCodeScanner = new PHPCodeScanner(fgColorProvider);
       fgHTMLCodeScanner = new HTMLCodeScanner(fgColorProvider);
       //               fgDocScanner= new JavaDocScanner(fgColorProvider);
     }
@@ -46,7 +46,7 @@ public class PHPEditorEnvironment {
    */
   public static void disconnect(Object client) {
     if (--fgRefCount == 0) {
-      fgCodeScanner = null;
+      fgPHPCodeScanner = null;
       fgHTMLCodeScanner = null;
       //                       fgDocScanner= null;
       fgColorProvider.dispose();
@@ -58,7 +58,7 @@ public class PHPEditorEnvironment {
    * Returns the singleton scanner.
    */
   public static PHPCodeScanner getPHPCodeScanner() {
-    return fgCodeScanner;
+    return fgPHPCodeScanner;
   }
 
   public static HTMLCodeScanner getHTMLCodeScanner() {
index 515f19f..e9376f5 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.ui.texteditor.TextEditorAction;
 public class PHPParserAction extends TextEditorAction {
 
   private static PHPParserAction instance = new PHPParserAction();
+  private static String[] EXTENSIONS = { ".php", ".php3", ".php4", ".inc", ".phtml" };
 
   protected IFile fileToParse;
   protected List fVariables = new ArrayList(100);
@@ -55,6 +56,7 @@ public class PHPParserAction extends TextEditorAction {
    * Code called when the action is fired.
    */
   public void run() {
+    boolean phpFlag = false;
     try {
       fileToParse = getPHPFile();
       if (fileToParse == null) {
@@ -63,22 +65,30 @@ public class PHPParserAction extends TextEditorAction {
         // should throw an exception
         return;
       }
-      IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-      if (store.getString(PHPeclipsePlugin.PHP_PARSER_DEFAULT).equals(PHPeclipsePlugin.PHP_INTERNAL_PARSER)) {
-        // first delete all the previous markers
-        fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
-
-        try {
-          InputStream iStream = fileToParse.getContents();
-          //        int c = iStream.read();
-          parse(iStream);
-          iStream.close();
-        } catch (IOException e) {
+      String name = fileToParse.getName();
+      for (int i = 0; i<EXTENSIONS.length; i++) {
+        if (name.endsWith(EXTENSIONS[i])) {
+          phpFlag = true;  // php file extension
+          break;
+        }
+      }
+      if (phpFlag) {
+        IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+        if (store.getString(PHPeclipsePlugin.PHP_PARSER_DEFAULT).equals(PHPeclipsePlugin.PHP_INTERNAL_PARSER)) {
+          // first delete all the previous markers
+          fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
+
+          try {
+            InputStream iStream = fileToParse.getContents();
+            //        int c = iStream.read();
+            parse(iStream);
+            iStream.close();
+          } catch (IOException e) {
+          }
+        } else {
+          PHPParser.phpExternalParse(fileToParse);
         }
-      } else {
-        PHPParser.phpExternalParse(fileToParse);
       }
-
     } catch (CoreException e) {
     }
 
@@ -143,9 +153,9 @@ public class PHPParserAction extends TextEditorAction {
 
   protected void parse(InputStream iStream) {
 
-    StringBuffer buf = new StringBuffer(); 
+    StringBuffer buf = new StringBuffer();
     int c0;
-    try { 
+    try {
       while ((c0 = iStream.read()) != (-1)) {
         buf.append((char) c0);
       }
index 80a8e6f..fe08e43 100644 (file)
@@ -101,7 +101,8 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
    * Method declared on SourceViewerConfiguration
    */
   public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
-    return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
+    return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null); //$NON-NLS-1$
+    // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
   }
 
   /* (non-Javadoc)
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCompletionProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCompletionProcessor.java
new file mode 100644 (file)
index 0000000..6857b46
--- /dev/null
@@ -0,0 +1,245 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. 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 implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.phpeditor.php;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import net.sourceforge.phpdt.internal.corext.template.ContextType;
+import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry;
+import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
+import net.sourceforge.phpdt.internal.ui.text.java.PHPCompletionProposalComparator;
+import net.sourceforge.phpdt.internal.ui.text.template.BuiltInEngine;
+import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine;
+import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPContentOutlinePage;
+import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationExtension;
+import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Example PHP completion processor.
+ */
+public class HTMLCompletionProcessor implements IContentAssistProcessor {
+
+  /**
+   * Simple content assist tip closer. The tip is valid in a range
+   * of 5 characters around its popup location.
+   */
+  protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
+
+    protected int fInstallOffset;
+
+    /*
+     * @see IContextInformationValidator#isContextInformationValid(int)
+     */
+    public boolean isContextInformationValid(int offset) {
+      return Math.abs(fInstallOffset - offset) < 5;
+    }
+
+    /*
+     * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
+     */
+    public void install(IContextInformation info, ITextViewer viewer, int offset) {
+      fInstallOffset = offset;
+    }
+
+    /*
+     * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
+     */
+    public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
+      return false;
+    }
+  };
+
+  private static class ContextInformationWrapper implements IContextInformation, IContextInformationExtension {
+
+    private final IContextInformation fContextInformation;
+    private int fPosition;
+
+    public ContextInformationWrapper(IContextInformation contextInformation) {
+      fContextInformation = contextInformation;
+    }
+
+    /*
+     * @see IContextInformation#getContextDisplayString()
+     */
+    public String getContextDisplayString() {
+      return fContextInformation.getContextDisplayString();
+    }
+
+    /*
+    * @see IContextInformation#getImage()
+    */
+    public Image getImage() {
+      return fContextInformation.getImage();
+    }
+
+    /*
+     * @see IContextInformation#getInformationDisplayString()
+     */
+    public String getInformationDisplayString() {
+      return fContextInformation.getInformationDisplayString();
+    }
+
+    /*
+     * @see IContextInformationExtension#getContextInformationPosition()
+     */
+    public int getContextInformationPosition() {
+      return fPosition;
+    }
+
+    public void setContextInformationPosition(int position) {
+      fPosition = position;
+    }
+  };
+
+  protected IContextInformationValidator fValidator = new Validator();
+  private TemplateEngine fTemplateEngine;
+  private PHPCompletionProposalComparator fComparator;
+  private int fNumberOfComputedResults = 0;
+
+  public HTMLCompletionProcessor() {
+
+    ContextType contextType = ContextTypeRegistry.getInstance().getContextType("html"); //$NON-NLS-1$
+    if (contextType != null)
+      fTemplateEngine = new TemplateEngine(contextType);
+
+    fComparator = new PHPCompletionProposalComparator();
+  }
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
+    int contextInformationPosition = guessContextInformationPosition(viewer, documentOffset);
+    return internalComputeCompletionProposals(viewer, documentOffset, contextInformationPosition);
+  }
+
+  private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset, int contextOffset) {
+    IDocument document = viewer.getDocument();
+    
+    if (fTemplateEngine != null) {
+      ICompletionProposal[] results;
+      //      try {
+      fTemplateEngine.reset();
+      fTemplateEngine.complete(viewer, offset); //, unit);
+      //      } catch (JavaModelException x) {
+      //        Shell shell= viewer.getTextWidget().getShell();
+      //        ErrorDialog.openError(shell, JavaTextMessages.getString("CompletionProcessor.error.accessing.title"), JavaTextMessages.getString("CompletionProcessor.error.accessing.message"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$
+      //      }       
+
+      IPHPCompletionProposal[] templateResults = fTemplateEngine.getResults();
+
+      // concatenate arrays
+      IPHPCompletionProposal[] total;
+      total = new IPHPCompletionProposal[templateResults.length];
+      System.arraycopy(templateResults, 0, total, 0, templateResults.length);
+      results = total;
+
+      fNumberOfComputedResults = (results == null ? 0 : results.length);
+      /*
+       * Order here and not in result collector to make sure that the order
+       * applies to all proposals and not just those of the compilation unit. 
+       */
+      return order(results);
+    }
+    return new IPHPCompletionProposal[0];
+  }
+
+  private int guessContextInformationPosition(ITextViewer viewer, int offset) {
+    int contextPosition = offset;
+    IDocument document = viewer.getDocument();
+    return contextPosition;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  //  public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
+  //    IContextInformation[] result = new IContextInformation[5];
+  //    for (int i = 0; i < result.length; i++)
+  //      result[i] = new ContextInformation(MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset)}), //$NON-NLS-1$
+  //      MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)})); //$NON-NLS-1$
+  //    return result;
+  //  }
+  /**
+   * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
+   */
+  public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+    int contextInformationPosition = guessContextInformationPosition(viewer, offset);
+    List result = addContextInformations(viewer, contextInformationPosition);
+    return (IContextInformation[]) result.toArray(new IContextInformation[result.size()]);
+  }
+
+  private List addContextInformations(ITextViewer viewer, int offset) {
+    ICompletionProposal[] proposals = internalComputeCompletionProposals(viewer, offset, -1);
+
+    List result = new ArrayList();
+    for (int i = 0; i < proposals.length; i++) {
+      IContextInformation contextInformation = proposals[i].getContextInformation();
+      if (contextInformation != null) {
+        ContextInformationWrapper wrapper = new ContextInformationWrapper(contextInformation);
+        wrapper.setContextInformationPosition(offset);
+        result.add(wrapper);
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Order the given proposals.
+   */
+  private ICompletionProposal[] order(ICompletionProposal[] proposals) {
+    Arrays.sort(proposals, fComparator);
+    return proposals;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public char[] getCompletionProposalAutoActivationCharacters() {
+    return new char[] { '<', '&', '#' };
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public char[] getContextInformationAutoActivationCharacters() {
+    return new char[] {
+    };
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public IContextInformationValidator getContextInformationValidator() {
+    return fValidator;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public String getErrorMessage() {
+    return null;
+  }
+}