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;
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;
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());
+ }
+
}
--- /dev/null
+/**********************************************************************
+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;
+ }
+}