Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 24783 Details for
Bug 102081
Abandon the combo box of preferenceDialog
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
A patch for 102081
0714OneClassWorkbench_final.txt (text/plain), 66.48 KB, created by
shujie liao
on 2005-07-14 15:14:47 EDT
(
hide
)
Description:
A patch for 102081
Filename:
MIME Type:
Creator:
shujie liao
Created:
2005-07-14 15:14:47 EDT
Size:
66.48 KB
patch
obsolete
>Index: Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java,v >retrieving revision 1.66 >diff -u -r1.66 FilteredPreferenceDialog.java >--- Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java 6 Jul 2005 18:12:09 -0000 1.66 >+++ Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java 14 Jul 2005 19:02:29 -0000 >@@ -57,7 +57,7 @@ > */ > public abstract class FilteredPreferenceDialog extends PreferenceDialog implements IWorkbenchPreferenceContainer{ > >- protected FilteredTextTree filteredTree; >+ protected FilteredTree filteredTree; > > private Object pageData; > >@@ -110,7 +110,7 @@ > protected TreeViewer createTreeViewer(Composite parent) { > PatternItemFilter filter = new PatternItemFilter(true); > int styleBits = SWT.SINGLE | SWT.H_SCROLL; >- filteredTree = new FilteredTextTree(parent, styleBits, filter); >+ filteredTree = new FilteredTree(parent, styleBits, filter); > GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); > gd.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN; > filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); >Index: Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTextTree.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTextTree.java >diff -N Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTextTree.java >--- Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTextTree.java 6 Jul 2005 18:12:09 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,342 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.ui.internal.dialogs; >- >-import java.util.ArrayList; >-import java.util.List; >- >-import org.eclipse.jface.dialogs.IDialogSettings; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.ControlAdapter; >-import org.eclipse.swt.events.ControlEvent; >-import org.eclipse.swt.events.DisposeEvent; >-import org.eclipse.swt.events.DisposeListener; >-import org.eclipse.swt.events.KeyAdapter; >-import org.eclipse.swt.events.KeyEvent; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.TraverseEvent; >-import org.eclipse.swt.events.TraverseListener; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.layout.GridLayout; >-import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.Listener; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.swt.widgets.Table; >-import org.eclipse.swt.widgets.TableItem; >-import org.eclipse.swt.widgets.Text; >-import org.eclipse.ui.internal.WorkbenchPlugin; >- >-/** >- * The FilteredTextTree is a filtered tree that uses an editable text. >- */ >-public class FilteredTextTree extends FilteredTree { >- // A list contains all strings in search history >- private List searchHistory; >- >- private static final String SEARCHHISTORY = "search"; //$NON-NLS-1$ >- >- // A table which contains only strings begin with typed strings >- private Table currentSeachTable; >- >- /** >- * Create a new instance of the receiver. >- * >- * @param parent >- * @param treeStyle >- */ >- public FilteredTextTree(Composite parent, int treeStyle) { >- super(parent, treeStyle); >- } >- >- /** >- * Create a new instance of the receiver with a supplied filter. >- * >- * @param parent >- * @param treeStyle >- * @param filter >- */ >- public FilteredTextTree(Composite parent, int treeStyle, >- PatternItemFilter filter) { >- super(parent, treeStyle, filter); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.ui.internal.dialogs.FilteredTree#createFilterControl(org.eclipse.swt.widgets.Composite) >- */ >- protected void createFilterControl(final Composite parent) { >- filterText = new Text(parent, SWT.DROP_DOWN | SWT.BORDER); >- filterText.setFont(parent.getFont()); >- searchHistory = getPreferenceSearchHistory(); >- >- final Shell shell = new Shell(parent.getShell(), SWT.NO_TRIM); >- shell >- .setBackground(parent.getDisplay().getSystemColor( >- SWT.COLOR_WHITE)); >- GridLayout shellGL = new GridLayout(); >- shellGL.marginHeight = 0; >- shellGL.marginWidth = 0; >- shell.setLayout(shellGL); >- shell.setLayoutData(new GridData( >- (GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); >- >- currentSeachTable = new Table(shell, SWT.SINGLE | SWT.BORDER); >- currentSeachTable.setLayoutData(new GridData( >- (GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); >- >- filterText.addTraverseListener(new TraverseListener() { >- public void keyTraversed(TraverseEvent e) { >- if (e.detail == SWT.TRAVERSE_RETURN) { >- e.doit = false; >- shell.setVisible(false); >- if (getViewer().getTree().getItemCount() == 0) { >- Display.getCurrent().beep(); >- setFilterText(""); //$NON-NLS-1$ >- } else { >- getViewer().getTree().setFocus(); >- } >- } >- } >- }); >- >- filterText.addKeyListener(new KeyAdapter() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) >- */ >- public void keyReleased(KeyEvent e) { >- >- if (e.keyCode == SWT.ARROW_DOWN) { >- if (currentSeachTable.isVisible()) { >- // Make selection at popup table >- if (currentSeachTable.getSelectionCount() < 1) >- currentSeachTable.setSelection(0); >- currentSeachTable.setFocus(); >- } else >- // Make selection be on the left tree >- treeViewer.getTree().setFocus(); >- } else { >- if (e.character == SWT.CR) >- return; >- >- textChanged(); >- List result = new ArrayList(); >- result = reduceSearch(searchHistory, filterText.getText()); >- upDateTable(currentSeachTable, result); >- >- if (currentSeachTable.getItemCount() > 0) { >- Rectangle textBounds = filterText.getBounds(); >- Point point = getDisplay().map(parent, null, >- textBounds.x, textBounds.y); >- int space = currentSeachTable.getItemHeight(); >- shell.setBounds(point.x, point.y + textBounds.height, >- textBounds.width, currentSeachTable >- .getItemHeight() >- * currentSeachTable.getItemCount() >- + space); >- >- if (shell.isDisposed()) >- shell.open(); >- >- if (!shell.getVisible()) { >- shell.setVisible(true); >- filterText.setFocus(); >- } >- >- } else >- shell.setVisible(false); >- } >- >- } >- }); >- >- parent.getDisplay().addFilter(SWT.MouseDown, new Listener() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Events) >- */ >- public void handleEvent(Event event) { >- if (!shell.isDisposed()) >- shell.setVisible(false); >- } >- }); >- >- getShell().addControlListener(new ControlAdapter() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent) >- */ >- public void controlMoved(ControlEvent e) { >- shell.setVisible(false); >- } >- }); >- >- currentSeachTable.addSelectionListener(new SelectionAdapter() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) >- */ >- public void widgetSelected(SelectionEvent e) { >- >- setFilterText(currentSeachTable.getSelection()[0].getText()); >- textChanged(); >- } >- >- public void widgetDefaultSelected(SelectionEvent e) { >- shell.setVisible(false); >- } >- }); >- >- filterText.addDisposeListener(new DisposeListener() { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) >- */ >- public void widgetDisposed(DisposeEvent e) { >- saveDialogSettings(); >- } >- }); >- >- filterText.getAccessible().addAccessibleListener( >- getAccessibleListener()); >- >- } >- >- /** >- * Find all items which start with typed words list the list contains all >- * strings of the search history >- * >- * @param list >- * the list to search >- * @param wordsEntered >- * String >- * @return a list in which all strings start from the typed letter(s) >- */ >- public List reduceSearch(List list, String wordsEntered) { >- List result = new ArrayList(); >- if (list == null) >- return result; >- for (int i = 0; i < list.size(); i++) { >- if (filterText.getText() == "") //$NON-NLS-1$ >- return result; >- else if (((String) list.get(i)).startsWith(wordsEntered)) >- result.add(list.get(i)); >- } >- >- return result; >- } >- >- /** >- * Copy all elements from a list to a table >- * >- * @param table >- * @param list >- */ >- public void upDateTable(Table table, List list) { >- table.removeAll(); >- if (list.size() > 0) { >- TableItem newItem; >- for (int i = 0; i < list.size(); i++) { >- newItem = new TableItem(table, SWT.NULL, i); >- newItem.setText((String) list.get(i)); >- >- } >- } >- >- } >- >- /** >- * Return a dialog setting section for this dialog >- * >- * @return IDialogSettings >- */ >- private IDialogSettings getDialogSettings() { >- IDialogSettings settings = WorkbenchPlugin.getDefault() >- .getDialogSettings(); >- IDialogSettings thisSettings = settings >- .getSection(getClass().getName()); >- if (thisSettings == null) >- thisSettings = settings.addNewSection(getClass().getName()); >- >- return thisSettings; >- } >- >- /** >- * Get the preferences search history for this eclipse's start, Note that >- * this history will not be cleared until this eclipse closes >- * >- * @return a list >- */ >- public List getPreferenceSearchHistory() { >- >- List searchList = new ArrayList(); >- IDialogSettings settings = getDialogSettings(); >- String[] search = settings.getArray(SEARCHHISTORY); //$NON-NLS-1$ >- >- if (search != null) { >- for (int i = 0; i < search.length; i++) >- searchList.add(search[i]); >- } >- return searchList; >- >- } >- >- /** >- * Saves the search history. >- */ >- private void saveDialogSettings() { >- IDialogSettings settings = getDialogSettings(); >- >- // If the settings contains the same key, the previous value will be >- // replaced by new one >- String[] result = new String[searchHistory.size()]; >- listToArray(searchHistory, result); >- settings.put(SEARCHHISTORY, result); >- >- } >- >- private void listToArray(List list, String[] string) { >- int size = list.size(); >- for (int i = 0; i < size; i++) >- string[i] = (String) list.get(i); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.ui.internal.dialogs.FilteredTree#filterFocusLost() >- */ >- protected void filterFocusLost() { >- String newText = filterText.getText(); >- Object[] textValues = searchHistory.toArray(); >- >- if ((newText.equals("")) || (newText.equals(initialText)))//$NON-NLS-1$ >- return; >- >- for (int i = 0; i < textValues.length; i++) { >- if (((String) textValues[i]).equals(newText)) >- return; >- } >- searchHistory.add(newText); >- } >- >-} >Index: Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTree.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTree.java,v >retrieving revision 1.29 >diff -u -r1.29 FilteredTree.java >--- Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTree.java 14 Jul 2005 13:35:23 -0000 1.29 >+++ Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTree.java 14 Jul 2005 19:02:29 -0000 >@@ -10,6 +10,9 @@ > *******************************************************************************/ > package org.eclipse.ui.internal.dialogs; > >+import java.util.ArrayList; >+import java.util.List; >+ > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; >@@ -17,6 +20,7 @@ > import org.eclipse.jface.action.Action; > import org.eclipse.jface.action.IAction; > import org.eclipse.jface.action.ToolBarManager; >+import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.resource.JFaceResources; > import org.eclipse.jface.viewers.TreeViewer; >@@ -24,20 +28,37 @@ > import org.eclipse.swt.SWT; > import org.eclipse.swt.accessibility.AccessibleAdapter; > import org.eclipse.swt.accessibility.AccessibleEvent; >+import org.eclipse.swt.events.ControlAdapter; >+import org.eclipse.swt.events.ControlEvent; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.FocusAdapter; > import org.eclipse.swt.events.FocusEvent; > import org.eclipse.swt.events.FocusListener; > import org.eclipse.swt.events.KeyAdapter; > import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.TraverseEvent; >+import org.eclipse.swt.events.TraverseListener; > import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.TableItem; > import org.eclipse.swt.widgets.Text; > import org.eclipse.swt.widgets.ToolBar; > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.internal.WorkbenchMessages; >+import org.eclipse.ui.internal.WorkbenchPlugin; > import org.eclipse.ui.plugin.AbstractUIPlugin; > import org.eclipse.ui.progress.WorkbenchJob; > >@@ -52,6 +73,17 @@ > > protected Text filterText; > >+ //A list contains all strings in search history >+ protected List searchHistory; >+ >+ //A key to match dialogsetting value >+ protected static final String SEARCHHISTORY = "search"; //$NON-NLS-1$ >+ >+ //A table which contains only strings begin with typed string(s) >+ private Table currentSeachTable; >+ >+ private Shell shell; >+ > private ToolBarManager filterToolBar; > > protected TreeViewer treeViewer; >@@ -148,6 +180,25 @@ > treeViewer = new TreeViewer(this, treeStyle); > data = new GridData(GridData.FILL_BOTH); > treeViewer.getControl().setLayoutData(data); >+ treeViewer.getControl().addFocusListener(new FocusAdapter(){ >+ /* Each time the tree gains focus, the current text in filterText is saved as search history >+ * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) >+ */ >+ public void focusGained(FocusEvent e) { >+ String newText = filterText.getText(); >+ Object[] textValues = searchHistory.toArray(); >+ >+ if((newText.equals(""))||(newText.equals(initialText)))//$NON-NLS-1$ >+ return; >+ >+ for (int i = 0; i < textValues.length; i++) { >+ if(((String)textValues[i]).equals(newText)) >+ return; >+ } >+ searchHistory.add(newText); >+ } >+ }); >+ > treeViewer.getControl().addDisposeListener(new DisposeListener(){ > /* (non-Javadoc) > * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) >@@ -206,33 +257,154 @@ > /** > * Create the filter control. > */ >- protected void createFilterControl(Composite parent) { >- filterText = new Text(parent, SWT.SINGLE | SWT.BORDER); >- filterText.getAccessible().addAccessibleListener(getAccessibleListener()); >- getFilterControl().addKeyListener(getKeyListener()); >+ protected void createFilterControl(final Composite parent) { >+ >+ filterText = new Text(parent, SWT.BORDER); >+ searchHistory = getPreferenceSearchHistory(); > >- } >+ shell = new Shell(parent.getShell(), SWT.NO_TRIM); >+ shell.setBackground(parent.getDisplay().getSystemColor( >+ SWT.COLOR_WHITE)); >+ GridLayout shellGL = new GridLayout(); >+ shellGL.marginHeight = 0; >+ shellGL.marginWidth = 0; >+ shell.setLayout(shellGL); >+ shell.setLayoutData(new GridData( >+ (GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); >+ >+ currentSeachTable = new Table(shell, SWT.SINGLE | SWT.BORDER); >+ currentSeachTable.setLayoutData(new GridData( >+ (GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); >+ >+ //Make sure show all text in the horizonal space through Changing the font size of table >+ Font font = parent.getFont(); >+ currentSeachTable.setFont(new Font >+ (parent.getDisplay(),font.getFontData()[0].getName(), >+ font.getFontData()[0].getHeight()-1,font.getFontData()[0].getStyle())); >+ >+ filterText.addTraverseListener(new TraverseListener() { >+ public void keyTraversed(TraverseEvent e) { >+ if (e.detail == SWT.TRAVERSE_RETURN) { >+ e.doit = false; >+ shell.setVisible(false); >+ if (getViewer().getTree().getItemCount() == 0) { >+ Display.getCurrent().beep(); >+ setFilterText(""); //$NON-NLS-1$ >+ } else { >+ getViewer().getTree().setFocus(); >+ } >+ } >+ } >+ }); >+ >+ /*filterText.addFocusListener(new FocusAdapter(){ >+ Focus has been gained on the filter control. >+ * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) >+ >+ public void focusGained(FocusEvent event) { >+ selectAll(); >+ >+ } >+ >+ });*/ >+ >+ filterText.addKeyListener(new KeyAdapter() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) >+ */ >+ public void keyReleased(KeyEvent e) { >+ >+ if (e.keyCode == SWT.ARROW_DOWN) { >+ if (currentSeachTable.isVisible()) { >+ // Set focus on the popup table >+ currentSeachTable.setFocus(); >+ currentSeachTable.setSelection(0); >+ } else >+ // Set focus on the left tree >+ treeViewer.getTree().setFocus(); >+ } else { >+ if (e.character == SWT.CR){ >+ int index =currentSeachTable.getSelectionIndex(); >+ setFilterText(currentSeachTable.getItem(index).getText()); >+ textChanged(); >+ shell.setVisible(false); >+ return; >+ } >+ textChanged(); >+ List result = new ArrayList(); >+ result = reduceSearch(searchHistory, filterText.getText()); >+ updateTable(currentSeachTable, result); >+ >+ if (currentSeachTable.getItemCount() > 0) { >+ Rectangle textBounds = filterText.getBounds(); >+ >+ setShellLocationAndSize(parent,textBounds); >+ >+ if (shell.isDisposed()) >+ shell.open(); >+ >+ if (!shell.getVisible()) { >+ shell.setVisible(true); >+ filterText.setFocus(); >+ } >+ >+ } else >+ shell.setVisible(false); >+ } >+ >+ } >+ }); >+ >+ parent.getDisplay().addFilter(SWT.MouseDown, new Listener() { >+ /* >+ * Anytime the parent composit detects a mouse down event, the eventhandler will set the shell unvisible >+ * >+ * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Events) >+ */ >+ public void handleEvent(Event event) { >+ if (!shell.isDisposed()) >+ shell.setVisible(false); >+ } >+ }); >+ >+ getShell().addControlListener(new ControlAdapter() { >+ /* >+ * Move dialog also make the popup shell not visible >+ * >+ * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent) >+ */ >+ public void controlMoved(ControlEvent e) { >+ shell.setVisible(false); >+ } >+ }); >+ >+ currentSeachTable.addSelectionListener(new SelectionAdapter() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) >+ */ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ shell.setVisible(false); >+ } >+ }); >+ >+ filterText.addDisposeListener(new DisposeListener() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) >+ */ >+ public void widgetDisposed(DisposeEvent e) { >+ saveDialogSettings(); >+ } >+ }); >+ >+ filterText.getAccessible().addAccessibleListener( >+ getAccessibleListener()); > >- /** >- * Get the key listener used for the receiver. >- * @return KeyListener >- */ >- protected KeyAdapter getKeyListener() { >- return new KeyAdapter() { >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) >- */ >- public void keyReleased(KeyEvent e) { >- // on a CR we want to transfer focus to the list >- if(e.keyCode == SWT.ARROW_DOWN) >- treeViewer.getTree().setFocus(); >- else >- textChanged(); >- } >- }; > } > > protected AccessibleAdapter getAccessibleListener() { >@@ -241,7 +413,7 @@ > * @see org.eclipse.swt.accessibility.AccessibleListener#getName(org.eclipse.swt.accessibility.AccessibleEvent) > */ > public void getName(AccessibleEvent e) { >- String filterTextString = getFilterText(); >+ String filterTextString = getFilterControlText(); > if(filterTextString.length() == 0){ > e.result = initialText; > } >@@ -253,13 +425,6 @@ > } > > /** >- * Get the text from the filter widget. >- * @return String >- */ >- protected String getFilterText() { >- return filterText.getText(); >- } >- /** > * update the receiver after the text has changed > */ > protected void textChanged() { >@@ -362,28 +527,10 @@ > */ > public void setInitialText(String text) { > initialText = text; >- setFilterText(initialText); >- >- textChanged(); >- listener = new FocusListener() { >- public void focusGained(FocusEvent event) { >- filterFocusGained(); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) >- */ >- public void focusLost(FocusEvent e) { >- filterFocusLost(); >- } >- }; >- getFilterControl().addFocusListener(listener); >+ setFilterText(initialText); >+ textChanged(); > } > >- >- > protected void selectAll() { > filterText.selectAll(); > } >@@ -419,20 +566,145 @@ > } > > /** >- * Focus has been gained on the filter control. >- * >+ * Find all items which start with typed words list the list contains all >+ * strings of the search history >+ * >+ * @param list >+ * the list to search >+ * @param wordsEntered >+ * String >+ * @return a list in which all strings start from the typed letter(s) > */ >- protected void filterFocusGained() { >- selectAll(); >- getFilterControl().removeFocusListener(listener); >+ protected List reduceSearch(List list, String wordsEntered) { >+ List result = new ArrayList(); >+ if (list == null) >+ return result; >+ for (int i = 0; i < list.size(); i++) { >+ if (filterText.getText() == "") //$NON-NLS-1$ >+ return result; >+ String historyString = (String) list.get(i); >+ String typedString = wordsEntered; >+ if (historyString.toLowerCase().startsWith(typedString.toLowerCase())) >+ result.add(historyString); >+ } >+ >+ return result; > } > > /** >- * Focus has been lost on the filter control. >- * >+ * Copy all elements from a list to a table >+ * >+ * @param table >+ * @param list > */ >- protected void filterFocusLost() { >+ protected void updateTable(Table table, List list) { >+ table.removeAll(); >+ if (list.size() > 0) { >+ TableItem newItem; >+ for (int i = 0; i < list.size(); i++) { >+ newItem = new TableItem(table, SWT.NULL, i); >+ newItem.setText((String) list.get(i)); >+ >+ } >+ } >+ >+ } >+ >+ /** >+ * Caculate and set the position and size of the popup shell >+ * @param parent >+ * @param textBounds >+ */ >+ public void setShellLocationAndSize(Composite parent, Rectangle textBounds){ >+ >+ //Caculate size of the popup shell >+ int space = currentSeachTable.getItemHeight(); >+ int tableHeight = currentSeachTable >+ .getItemHeight()* currentSeachTable.getItemCount() + space; >+ int tableWidth = textBounds.width; >+ shell.setSize(tableWidth,tableHeight); >+ >+ //Caculate x,y coordinator of the popup shell >+ Point point = getDisplay().map(parent, null, >+ textBounds.x, textBounds.y); >+ final int xCoord = point.x; >+ final int yCoord = point.y + textBounds.height; >+ >+ final Point location = new Point(xCoord, yCoord); >+ >+ //Try to show whole popup shell through relocating its x and y coordinator >+ final Display display = shell.getDisplay(); >+ final Rectangle displayBounds = display.getClientArea(); >+ final int displayRightEdge = displayBounds.x + displayBounds.width; > >+ if (location.x <0) >+ location.x = 0; >+ if ((location.x + tableWidth) > displayRightEdge) >+ location.x = displayRightEdge - tableWidth; >+ >+ final int displayBottomEdge = displayBounds.y + displayBounds.height; >+ if ((location.y + tableHeight) > displayBottomEdge) >+ location.y = displayBottomEdge - tableHeight; >+ >+ // Set the location. >+ shell.setLocation(location); >+ } >+ /** >+ * Return a dialog setting section for this dialog >+ * >+ * @return IDialogSettings >+ */ >+ >+ >+ private IDialogSettings getDialogSettings() { >+ IDialogSettings settings = WorkbenchPlugin.getDefault() >+ .getDialogSettings(); >+ IDialogSettings thisSettings = settings >+ .getSection(getClass().getName()); >+ if (thisSettings == null) >+ thisSettings = settings.addNewSection(getClass().getName()); >+ >+ return thisSettings; >+ } >+ >+ /** >+ * Get the preferences search history for this eclipse's start, Note that >+ * this history will not be cleared until this eclipse closes >+ * >+ * @return a list >+ */ >+ public List getPreferenceSearchHistory() { >+ >+ List searchList = new ArrayList(); >+ IDialogSettings settings = getDialogSettings(); >+ String[] search = settings.getArray(SEARCHHISTORY); //$NON-NLS-1$ >+ >+ if (search != null) { >+ for (int i = 0; i < search.length; i++) >+ searchList.add(search[i]); >+ } >+ return searchList; >+ > } >+ >+ /** >+ * Saves the search history. >+ */ >+ private void saveDialogSettings() { >+ IDialogSettings settings = getDialogSettings(); >+ >+ // If the settings contains the same key, the previous value will be >+ // replaced by new one >+ String[] result = new String[searchHistory.size()]; >+ listToArray(searchHistory, result); >+ settings.put(SEARCHHISTORY, result); >+ >+ } >+ >+ private void listToArray(List list, String[] string) { >+ int size = list.size(); >+ for (int i = 0; i < size; i++) >+ string[i] = (String) list.get(i); >+ } > > } >Index: Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java,v >retrieving revision 1.3 >diff -u -r1.3 PreferenceBoldLabelProvider.java >--- Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java 6 Jul 2005 18:12:09 -0000 1.3 >+++ Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java 14 Jul 2005 19:02:29 -0000 >@@ -14,10 +14,10 @@ > implements IFontProvider { > > >- private FilteredTextTree comboTree; >+ private FilteredTree filteredTree; > >- PreferenceBoldLabelProvider(FilteredTextTree comboTree) { >- this.comboTree = comboTree; >+ PreferenceBoldLabelProvider(FilteredTree theTree) { >+ this.filteredTree = theTree; > } > /** > * Using "false" to construct the filter so that this filter can filter >@@ -27,24 +27,24 @@ > > public Font getFont(Object element) { > >- String filterText = comboTree.getFilterControlText(); >+ String filterText = filteredTree.getFilterControlText(); > > // Do nothing if it's empty string >- if (!(filterText.equals("") || filterText.equals(comboTree.getInitialText()))) {//$NON-NLS-1$ >+ if (!(filterText.equals("") || filterText.equals(filteredTree.getInitialText()))) {//$NON-NLS-1$ > >- boolean initial = comboTree.getInitialText() != null >- && filterText.equals(comboTree.getInitialText()); >+ boolean initial = filteredTree.getInitialText() != null >+ && filterText.equals(filteredTree.getInitialText()); > if (initial) { > filterForBoldElements.setPattern(null); > } else { > filterForBoldElements.setPattern(filterText); > } > >- ITreeContentProvider contentProvider = (ITreeContentProvider) comboTree.getViewer() >+ ITreeContentProvider contentProvider = (ITreeContentProvider) filteredTree.getViewer() > .getContentProvider(); > Object parent = contentProvider.getParent(element); > >- if (filterForBoldElements.select(comboTree.getViewer(), parent, element)) { >+ if (filterForBoldElements.select(filteredTree.getViewer(), parent, element)) { > return JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT); > } > } >Index: Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java,v >retrieving revision 1.3 >diff -u -r1.3 NewKeysPreferencePage.java >--- Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java 7 Jul 2005 20:08:36 -0000 1.3 >+++ Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java 14 Jul 2005 19:02:29 -0000 >@@ -1 +1 @@ >-/******************************************************************************* * Copyright (c) 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation ******************************************************************************/ package org.eclipse.ui.internal.keys; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.ResourceBundle; import java.util.Set; import org.eclipse.core.commands.CommandManager; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.contexts.ContextManager; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.bindings.Binding; import org.eclipse.jface.bindings.BindingManager; import org.eclipse.jface.bindings.Scheme; import org.eclipse.jface.bindings.keys.KeySequence; import org.eclipse.jface.bindings.keys.KeySequenceText; import org.eclipse.jface.bindings.keys.KeyStroke; import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.jface.contexts.IContextIds; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.NamedHandleObjectLabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.dialogs.FilteredTextTree; import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.keys.IBindingService; /** * @since 3.1 */ public final class NewKeysPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** * The resource bundle from which translations can be retrieved. */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(NewKeysPreferencePage.class.getName()); private IBindingService bindingService = null; private IContextService contextService = null; /** * A binding manager local to this preference page. When the page is * initialized, the current bindings are read out from the binding service * and placed in this manager. This manager is then updated as the user * makes changes. When the user has finished, the contents of this manager * are compared with the contents of the binding service. The changes are * then persisted. */ private final BindingManager localChangeManager = new BindingManager( new ContextManager(), new CommandManager()); private ComboViewer schemeCombo = null; private ComboViewer whenCombo = null; private final Control createButtonBar(final Composite parent) { GridLayout layout; GridData gridData; int widthHint; // Create the composite to house the button bar. final Composite buttonBar = new Composite(parent, SWT.NONE); layout = new GridLayout(1, false); layout.marginWidth = 0; buttonBar.setLayout(layout); gridData = new GridData(); gridData.horizontalAlignment = SWT.END; buttonBar.setLayoutData(gridData); // Advanced button. final Button advancedButton = new Button(buttonBar, SWT.PUSH); gridData = new GridData(); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); advancedButton.setText(Util.translateString(RESOURCE_BUNDLE, "advancedButton.Text")); //$NON-NLS-1$ gridData.widthHint = Math.max(widthHint, advancedButton.computeSize( SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; advancedButton.setLayoutData(gridData); return buttonBar; } /* * (non-Javadoc) * * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) */ protected final Control createContents(final Composite parent) { GridData gridData = null; GridLayout layout = null; int widthHint; // Creates a composite to hold all of the page contents. final Composite page = new Composite(parent, SWT.NONE); layout = new GridLayout(1, false); layout.marginWidth = 0; page.setLayout(layout); createSchemeControls(page); createTree(page); createTreeControls(page); createDataControls(page); createButtonBar(page); update(true); return page; } private final Control createDataControls(final Composite parent) { GridLayout layout; GridData gridData; // Creates the data area. final Composite dataArea = new Composite(parent, SWT.NONE); layout = new GridLayout(5, false); layout.marginWidth = 0; dataArea.setLayout(layout); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; dataArea.setLayoutData(gridData); // FIRST ROW // The command name label. final Label commandNameLabel = new Label(dataArea, SWT.NONE); commandNameLabel.setText(Util.translateString(RESOURCE_BUNDLE, "commandNameLabel.Text")); //$NON-NLS-1$); //$NON-NLS-1$ // The current command name. final Label commandNameValueLabel = new Label(dataArea, SWT.NONE); // TODO This should be update dynamically commandNameValueLabel.setText("Word Completion"); //$NON-NLS-1$ gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.horizontalAlignment = SWT.BEGINNING; commandNameValueLabel.setLayoutData(gridData); // The binding label. final Label bindingLabel = new Label(dataArea, SWT.NONE); bindingLabel.setText(Util.translateString(RESOURCE_BUNDLE, "bindingLabel.Text")); //$NON-NLS-1$ // The key sequence entry widget. final Text bindingText = new Text(dataArea, SWT.BORDER); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.widthHint = 300; bindingText.setLayoutData(gridData); final KeySequenceText keySequenceText = new KeySequenceText(bindingText); try { keySequenceText.setKeySequence(KeySequence.getInstance("ALT+/")); //$NON-NLS-1$ } catch (final ParseException e) { // TODO This should be done dynamically. } keySequenceText.setKeyStrokeLimit(4); // Button for adding trapped key strokes final Button addKeyButton = new Button(dataArea, SWT.LEFT | SWT.ARROW); addKeyButton.setToolTipText(Util.translateString(RESOURCE_BUNDLE, "addKeyButton.ToolTipText")); //$NON-NLS-1$ gridData = new GridData(); gridData.heightHint = schemeCombo.getCombo().getTextHeight(); addKeyButton.setLayoutData(gridData); // Arrow buttons aren't normally added to the tab list. Let's fix that. final Control[] tabStops = dataArea.getTabList(); final ArrayList newTabStops = new ArrayList(); for (int i = 0; i < tabStops.length; i++) { Control tabStop = tabStops[i]; newTabStops.add(tabStop); if (bindingText.equals(tabStop)) { newTabStops.add(addKeyButton); } } final Control[] newTabStopArray = (Control[]) newTabStops .toArray(new Control[newTabStops.size()]); dataArea.setTabList(newTabStopArray); // Construct the menu to attach to the above button. final Menu addKeyMenu = new Menu(addKeyButton); final Iterator trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator(); while (trappedKeyItr.hasNext()) { final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next(); final MenuItem menuItem = new MenuItem(addKeyMenu, SWT.PUSH); menuItem.setText(trappedKey.format()); menuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { keySequenceText.insert(trappedKey); bindingText.setFocus(); bindingText.setSelection(bindingText.getTextLimit()); } }); } addKeyButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent selectionEvent) { Point buttonLocation = addKeyButton.getLocation(); buttonLocation = dataArea.toDisplay(buttonLocation.x, buttonLocation.y); Point buttonSize = addKeyButton.getSize(); addKeyMenu.setLocation(buttonLocation.x, buttonLocation.y + buttonSize.y); addKeyMenu.setVisible(true); } }); // SECOND ROW. // The description label. final Label descriptionLabel = new Label(dataArea, SWT.NONE); descriptionLabel.setText(Util.translateString(RESOURCE_BUNDLE, "descriptionLabel.Text")); //$NON-NLS-1$ gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.horizontalSpan = 2; descriptionLabel.setLayoutData(gridData); // The when label. final Label whenLabel = new Label(dataArea, SWT.NONE); whenLabel.setText(Util.translateString(RESOURCE_BUNDLE, "whenLabel.Text")); //$NON-NLS-1$ // The when combo. whenCombo = new ComboViewer(dataArea); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.horizontalSpan = 2; whenCombo.getCombo().setLayoutData(gridData); whenCombo.setLabelProvider(new NamedHandleObjectLabelProvider()); whenCombo.setContentProvider(new ArrayContentProvider()); // THIRD ROW. // The description value. final Label descriptionValueLabel = new Label(dataArea, SWT.WRAP); // TODO This value should be updated dynamically. descriptionValueLabel.setText("Context insensitive completion"); //$NON-NLS-1$ gridData = new GridData(); gridData.horizontalSpan = 5; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalIndent = 30; gridData.verticalIndent = 5; descriptionValueLabel.setLayoutData(gridData); return dataArea; } private final Control createSchemeControls(final Composite parent) { GridLayout layout; GridData gridData; int widthHint; // Create a composite to hold the controls. final Composite schemeControls = new Composite(parent, SWT.NONE); layout = new GridLayout(3, false); layout.marginWidth = 0; schemeControls.setLayout(layout); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; schemeControls.setLayoutData(gridData); // Create the label. final Label schemeLabel = new Label(schemeControls, SWT.NONE); schemeLabel.setText(Util.translateString(RESOURCE_BUNDLE, "schemeLabel.Text")); //$NON-NLS-1$ // Create the combo. schemeCombo = new ComboViewer(schemeControls); schemeCombo.setLabelProvider(new NamedHandleObjectLabelProvider()); schemeCombo.setContentProvider(new ArrayContentProvider()); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; schemeCombo.getCombo().setLayoutData(gridData); // Create the delete button. final Button deleteSchemeButton = new Button(schemeControls, SWT.PUSH); gridData = new GridData(); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); deleteSchemeButton.setText(Util.translateString(RESOURCE_BUNDLE, "deleteSchemeButton.Text")); //$NON-NLS-1$ gridData.widthHint = Math.max(widthHint, deleteSchemeButton .computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; deleteSchemeButton.setLayoutData(gridData); return schemeControls; } private final Control createTree(final Composite parent) { GridData gridData; // Creates the filtered tree. final FilteredTextTree filteredTree = new FilteredTextTree(parent, SWT.SINGLE | SWT.FULL_SELECTION); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.verticalAlignment = SWT.FILL; filteredTree.setLayoutData(gridData); return filteredTree; } private final Control createTreeControls(final Composite parent) { GridLayout layout; GridData gridData; int widthHint; // Creates controls related to the tree. final Composite treeControls = new Composite(parent, SWT.NONE); layout = new GridLayout(2, false); layout.marginWidth = 0; treeControls.setLayout(layout); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; treeControls.setLayoutData(gridData); // Create the show all check box. final Button showAllCheckBox = new Button(treeControls, SWT.CHECK); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; showAllCheckBox.setLayoutData(gridData); showAllCheckBox.setText(Util.translateString(RESOURCE_BUNDLE, "showAllCheckBox.Text")); //$NON-NLS-1$ // Create the delete binding button. final Button deleteBindingButton = new Button(treeControls, SWT.PUSH); gridData = new GridData(); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); deleteBindingButton.setText(Util.translateString(RESOURCE_BUNDLE, "deleteBindingButton.Text")); //$NON-NLS-1$ gridData.widthHint = Math.max(widthHint, deleteBindingButton .computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; deleteBindingButton.setLayoutData(gridData); return treeControls; } /* * (non-Javadoc) * * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */ public final void init(final IWorkbench workbench) { bindingService = (IBindingService) workbench .getAdapter(IBindingService.class); contextService = (IContextService) workbench .getAdapter(IContextService.class); } /** * Logs the given exception, and opens an error dialog saying that something * went wrong. The exception is assumed to have something to do with the * preference store. * * @param exception * The exception to be logged; must not be <code>null</code>. */ private final void logPreferenceStoreException(final Throwable exception) { final String message = Util.translateString(RESOURCE_BUNDLE, "PreferenceStoreError.Message"); //$NON-NLS-1$ final String title = Util.translateString(RESOURCE_BUNDLE, "PreferenceStoreError.Title"); //$NON-NLS-1$ String exceptionMessage = exception.getMessage(); if (exceptionMessage == null) { exceptionMessage = message; } final IStatus status = new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, 0, exceptionMessage, exception); WorkbenchPlugin.log(message, status); ErrorDialog.openError(schemeCombo.getCombo().getShell(), title, message, status); } protected final void performDefaults() { // Ask the user to confirm final String title = Util.translateString(RESOURCE_BUNDLE, "restoreDefaultsMessageBoxText"); //$NON-NLS-1$ final String message = Util.translateString(RESOURCE_BUNDLE, "restoreDefaultsMessageBoxMessage"); //$NON-NLS-1$ final boolean confirmed = MessageDialog.openConfirm(getShell(), title, message); if (confirmed) { // Fix the scheme in the local changes. final String defaultSchemeId = bindingService.getDefaultSchemeId(); final Scheme defaultScheme = localChangeManager .getScheme(defaultSchemeId); try { localChangeManager.setActiveScheme(defaultScheme); } catch (final NotDefinedException e) { // At least we tried.... } // Fix the bindings in the local changes. final Binding[] currentBindings = localChangeManager.getBindings(); final int currentBindingsLength = currentBindings.length; final Set trimmedBindings = new HashSet(); for (int i = 0; i < currentBindingsLength; i++) { final Binding binding = currentBindings[i]; if (binding.getType() != Binding.USER) { trimmedBindings.add(binding); } } final Binding[] trimmedBindingArray = (Binding[]) trimmedBindings .toArray(new Binding[trimmedBindings.size()]); localChangeManager.setBindings(trimmedBindingArray); // Apply the changes. try { bindingService.savePreferences(defaultScheme, trimmedBindingArray); } catch (final IOException e) { logPreferenceStoreException(e); } } setScheme(localChangeManager.getActiveScheme()); super.performDefaults(); } public final boolean performOk() { // Save the preferences. try { bindingService.savePreferences( localChangeManager.getActiveScheme(), localChangeManager .getBindings()); } catch (final IOException e) { logPreferenceStoreException(e); } return super.performOk(); } /** * Sets the currently selected scheme. Setting the scheme always triggers * an update of the underlying widgets. * * @param scheme * The scheme to select; may be <code>null</code>. */ private final void setScheme(final Scheme scheme) { schemeCombo.setSelection(new StructuredSelection(scheme)); } private final void update(final boolean registryChanged) { updateSchemeCombo(registryChanged); updateWhenCombo(registryChanged); } private final void updateSchemeCombo(final boolean registryChanged) { if (registryChanged) { // TODO This should be sorted alphabetically. schemeCombo.setInput(bindingService.getDefinedSchemes()); setScheme(bindingService.getActiveScheme()); } } private final void updateWhenCombo(final boolean registryChanged) { if (registryChanged) { // TODO This should be sorted alphabetically. whenCombo.setInput(contextService.getDefinedContexts()); // TODO This should be updated based on the active context/ whenCombo.setSelection(new StructuredSelection(contextService .getContext(IContextIds.CONTEXT_ID_WINDOW)), true); } } } >\ No newline at end of file >+/******************************************************************************* * Copyright (c) 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation ******************************************************************************/ package org.eclipse.ui.internal.keys; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.ResourceBundle; import java.util.Set; import org.eclipse.core.commands.CommandManager; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.contexts.ContextManager; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.bindings.Binding; import org.eclipse.jface.bindings.BindingManager; import org.eclipse.jface.bindings.Scheme; import org.eclipse.jface.bindings.keys.KeySequence; import org.eclipse.jface.bindings.keys.KeySequenceText; import org.eclipse.jface.bindings.keys.KeyStroke; import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.jface.contexts.IContextIds; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.NamedHandleObjectLabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.dialogs.FilteredTree; import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.keys.IBindingService; /** * @since 3.1 */ public final class NewKeysPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** * The resource bundle from which translations can be retrieved. */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(NewKeysPreferencePage.class.getName()); private IBindingService bindingService = null; private IContextService contextService = null; /** * A binding manager local to this preference page. When the page is * initialized, the current bindings are read out from the binding service * and placed in this manager. This manager is then updated as the user * makes changes. When the user has finished, the contents of this manager * are compared with the contents of the binding service. The changes are * then persisted. */ private final BindingManager localChangeManager = new BindingManager( new ContextManager(), new CommandManager()); private ComboViewer schemeCombo = null; private ComboViewer whenCombo = null; private final Control createButtonBar(final Composite parent) { GridLayout layout; GridData gridData; int widthHint; // Create the composite to house the button bar. final Composite buttonBar = new Composite(parent, SWT.NONE); layout = new GridLayout(1, false); layout.marginWidth = 0; buttonBar.setLayout(layout); gridData = new GridData(); gridData.horizontalAlignment = SWT.END; buttonBar.setLayoutData(gridData); // Advanced button. final Button advancedButton = new Button(buttonBar, SWT.PUSH); gridData = new GridData(); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); advancedButton.setText(Util.translateString(RESOURCE_BUNDLE, "advancedButton.Text")); //$NON-NLS-1$ gridData.widthHint = Math.max(widthHint, advancedButton.computeSize( SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; advancedButton.setLayoutData(gridData); return buttonBar; } /* * (non-Javadoc) * * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) */ protected final Control createContents(final Composite parent) { GridData gridData = null; GridLayout layout = null; int widthHint; // Creates a composite to hold all of the page contents. final Composite page = new Composite(parent, SWT.NONE); layout = new GridLayout(1, false); layout.marginWidth = 0; page.setLayout(layout); createSchemeControls(page); createTree(page); createTreeControls(page); createDataControls(page); createButtonBar(page); update(true); return page; } private final Control createDataControls(final Composite parent) { GridLayout layout; GridData gridData; // Creates the data area. final Composite dataArea = new Composite(parent, SWT.NONE); layout = new GridLayout(5, false); layout.marginWidth = 0; dataArea.setLayout(layout); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; dataArea.setLayoutData(gridData); // FIRST ROW // The command name label. final Label commandNameLabel = new Label(dataArea, SWT.NONE); commandNameLabel.setText(Util.translateString(RESOURCE_BUNDLE, "commandNameLabel.Text")); //$NON-NLS-1$); //$NON-NLS-1$ // The current command name. final Label commandNameValueLabel = new Label(dataArea, SWT.NONE); // TODO This should be update dynamically commandNameValueLabel.setText("Word Completion"); //$NON-NLS-1$ gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.horizontalAlignment = SWT.BEGINNING; commandNameValueLabel.setLayoutData(gridData); // The binding label. final Label bindingLabel = new Label(dataArea, SWT.NONE); bindingLabel.setText(Util.translateString(RESOURCE_BUNDLE, "bindingLabel.Text")); //$NON-NLS-1$ // The key sequence entry widget. final Text bindingText = new Text(dataArea, SWT.BORDER); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.widthHint = 300; bindingText.setLayoutData(gridData); final KeySequenceText keySequenceText = new KeySequenceText(bindingText); try { keySequenceText.setKeySequence(KeySequence.getInstance("ALT+/")); //$NON-NLS-1$ } catch (final ParseException e) { // TODO This should be done dynamically. } keySequenceText.setKeyStrokeLimit(4); // Button for adding trapped key strokes final Button addKeyButton = new Button(dataArea, SWT.LEFT | SWT.ARROW); addKeyButton.setToolTipText(Util.translateString(RESOURCE_BUNDLE, "addKeyButton.ToolTipText")); //$NON-NLS-1$ gridData = new GridData(); gridData.heightHint = schemeCombo.getCombo().getTextHeight(); addKeyButton.setLayoutData(gridData); // Arrow buttons aren't normally added to the tab list. Let's fix that. final Control[] tabStops = dataArea.getTabList(); final ArrayList newTabStops = new ArrayList(); for (int i = 0; i < tabStops.length; i++) { Control tabStop = tabStops[i]; newTabStops.add(tabStop); if (bindingText.equals(tabStop)) { newTabStops.add(addKeyButton); } } final Control[] newTabStopArray = (Control[]) newTabStops .toArray(new Control[newTabStops.size()]); dataArea.setTabList(newTabStopArray); // Construct the menu to attach to the above button. final Menu addKeyMenu = new Menu(addKeyButton); final Iterator trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator(); while (trappedKeyItr.hasNext()) { final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next(); final MenuItem menuItem = new MenuItem(addKeyMenu, SWT.PUSH); menuItem.setText(trappedKey.format()); menuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { keySequenceText.insert(trappedKey); bindingText.setFocus(); bindingText.setSelection(bindingText.getTextLimit()); } }); } addKeyButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent selectionEvent) { Point buttonLocation = addKeyButton.getLocation(); buttonLocation = dataArea.toDisplay(buttonLocation.x, buttonLocation.y); Point buttonSize = addKeyButton.getSize(); addKeyMenu.setLocation(buttonLocation.x, buttonLocation.y + buttonSize.y); addKeyMenu.setVisible(true); } }); // SECOND ROW. // The description label. final Label descriptionLabel = new Label(dataArea, SWT.NONE); descriptionLabel.setText(Util.translateString(RESOURCE_BUNDLE, "descriptionLabel.Text")); //$NON-NLS-1$ gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.horizontalSpan = 2; descriptionLabel.setLayoutData(gridData); // The when label. final Label whenLabel = new Label(dataArea, SWT.NONE); whenLabel.setText(Util.translateString(RESOURCE_BUNDLE, "whenLabel.Text")); //$NON-NLS-1$ // The when combo. whenCombo = new ComboViewer(dataArea); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.horizontalSpan = 2; whenCombo.getCombo().setLayoutData(gridData); whenCombo.setLabelProvider(new NamedHandleObjectLabelProvider()); whenCombo.setContentProvider(new ArrayContentProvider()); // THIRD ROW. // The description value. final Label descriptionValueLabel = new Label(dataArea, SWT.WRAP); // TODO This value should be updated dynamically. descriptionValueLabel.setText("Context insensitive completion"); //$NON-NLS-1$ gridData = new GridData(); gridData.horizontalSpan = 5; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; gridData.horizontalIndent = 30; gridData.verticalIndent = 5; descriptionValueLabel.setLayoutData(gridData); return dataArea; } private final Control createSchemeControls(final Composite parent) { GridLayout layout; GridData gridData; int widthHint; // Create a composite to hold the controls. final Composite schemeControls = new Composite(parent, SWT.NONE); layout = new GridLayout(3, false); layout.marginWidth = 0; schemeControls.setLayout(layout); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; schemeControls.setLayoutData(gridData); // Create the label. final Label schemeLabel = new Label(schemeControls, SWT.NONE); schemeLabel.setText(Util.translateString(RESOURCE_BUNDLE, "schemeLabel.Text")); //$NON-NLS-1$ // Create the combo. schemeCombo = new ComboViewer(schemeControls); schemeCombo.setLabelProvider(new NamedHandleObjectLabelProvider()); schemeCombo.setContentProvider(new ArrayContentProvider()); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; schemeCombo.getCombo().setLayoutData(gridData); // Create the delete button. final Button deleteSchemeButton = new Button(schemeControls, SWT.PUSH); gridData = new GridData(); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); deleteSchemeButton.setText(Util.translateString(RESOURCE_BUNDLE, "deleteSchemeButton.Text")); //$NON-NLS-1$ gridData.widthHint = Math.max(widthHint, deleteSchemeButton .computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; deleteSchemeButton.setLayoutData(gridData); return schemeControls; } private final Control createTree(final Composite parent) { GridData gridData; // Creates the filtered tree. final FilteredTree filteredTree = new FilteredTree(parent, SWT.SINGLE | SWT.FULL_SELECTION); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = SWT.FILL; gridData.verticalAlignment = SWT.FILL; filteredTree.setLayoutData(gridData); return filteredTree; } private final Control createTreeControls(final Composite parent) { GridLayout layout; GridData gridData; int widthHint; // Creates controls related to the tree. final Composite treeControls = new Composite(parent, SWT.NONE); layout = new GridLayout(2, false); layout.marginWidth = 0; treeControls.setLayout(layout); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; treeControls.setLayoutData(gridData); // Create the show all check box. final Button showAllCheckBox = new Button(treeControls, SWT.CHECK); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; showAllCheckBox.setLayoutData(gridData); showAllCheckBox.setText(Util.translateString(RESOURCE_BUNDLE, "showAllCheckBox.Text")); //$NON-NLS-1$ // Create the delete binding button. final Button deleteBindingButton = new Button(treeControls, SWT.PUSH); gridData = new GridData(); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); deleteBindingButton.setText(Util.translateString(RESOURCE_BUNDLE, "deleteBindingButton.Text")); //$NON-NLS-1$ gridData.widthHint = Math.max(widthHint, deleteBindingButton .computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x) + 5; deleteBindingButton.setLayoutData(gridData); return treeControls; } /* * (non-Javadoc) * * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */ public final void init(final IWorkbench workbench) { bindingService = (IBindingService) workbench .getAdapter(IBindingService.class); contextService = (IContextService) workbench .getAdapter(IContextService.class); } /** * Logs the given exception, and opens an error dialog saying that something * went wrong. The exception is assumed to have something to do with the * preference store. * * @param exception * The exception to be logged; must not be <code>null</code>. */ private final void logPreferenceStoreException(final Throwable exception) { final String message = Util.translateString(RESOURCE_BUNDLE, "PreferenceStoreError.Message"); //$NON-NLS-1$ final String title = Util.translateString(RESOURCE_BUNDLE, "PreferenceStoreError.Title"); //$NON-NLS-1$ String exceptionMessage = exception.getMessage(); if (exceptionMessage == null) { exceptionMessage = message; } final IStatus status = new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, 0, exceptionMessage, exception); WorkbenchPlugin.log(message, status); ErrorDialog.openError(schemeCombo.getCombo().getShell(), title, message, status); } protected final void performDefaults() { // Ask the user to confirm final String title = Util.translateString(RESOURCE_BUNDLE, "restoreDefaultsMessageBoxText"); //$NON-NLS-1$ final String message = Util.translateString(RESOURCE_BUNDLE, "restoreDefaultsMessageBoxMessage"); //$NON-NLS-1$ final boolean confirmed = MessageDialog.openConfirm(getShell(), title, message); if (confirmed) { // Fix the scheme in the local changes. final String defaultSchemeId = bindingService.getDefaultSchemeId(); final Scheme defaultScheme = localChangeManager .getScheme(defaultSchemeId); try { localChangeManager.setActiveScheme(defaultScheme); } catch (final NotDefinedException e) { // At least we tried.... } // Fix the bindings in the local changes. final Binding[] currentBindings = localChangeManager.getBindings(); final int currentBindingsLength = currentBindings.length; final Set trimmedBindings = new HashSet(); for (int i = 0; i < currentBindingsLength; i++) { final Binding binding = currentBindings[i]; if (binding.getType() != Binding.USER) { trimmedBindings.add(binding); } } final Binding[] trimmedBindingArray = (Binding[]) trimmedBindings .toArray(new Binding[trimmedBindings.size()]); localChangeManager.setBindings(trimmedBindingArray); // Apply the changes. try { bindingService.savePreferences(defaultScheme, trimmedBindingArray); } catch (final IOException e) { logPreferenceStoreException(e); } } setScheme(localChangeManager.getActiveScheme()); super.performDefaults(); } public final boolean performOk() { // Save the preferences. try { bindingService.savePreferences( localChangeManager.getActiveScheme(), localChangeManager .getBindings()); } catch (final IOException e) { logPreferenceStoreException(e); } return super.performOk(); } /** * Sets the currently selected scheme. Setting the scheme always triggers * an update of the underlying widgets. * * @param scheme * The scheme to select; may be <code>null</code>. */ private final void setScheme(final Scheme scheme) { schemeCombo.setSelection(new StructuredSelection(scheme)); } private final void update(final boolean registryChanged) { updateSchemeCombo(registryChanged); updateWhenCombo(registryChanged); } private final void updateSchemeCombo(final boolean registryChanged) { if (registryChanged) { // TODO This should be sorted alphabetically. schemeCombo.setInput(bindingService.getDefinedSchemes()); setScheme(bindingService.getActiveScheme()); } } private final void updateWhenCombo(final boolean registryChanged) { if (registryChanged) { // TODO This should be sorted alphabetically. whenCombo.setInput(contextService.getDefinedContexts()); // TODO This should be updated based on the active context/ whenCombo.setSelection(new StructuredSelection(contextService .getContext(IContextIds.CONTEXT_ID_WINDOW)), true); } } }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 102081
:
24326
|
24383
|
24783
|
25296
|
25430
|
25584
|
27648
|
27653
|
27838
|
27868
|
27957
|
27967
|
27979
|
28401
|
28603