1414 * Lars Vogel <Lars.Vogel@vogella.com> - Bug 472654, 491272, 491398
1515 * Leung Wang Hei <gemaspecial@yahoo.com.hk> - Bug 483343
1616 * Patrik Suzzi <psuzzi@gmail.com> - Bug 491291, 491529, 491293, 492434, 492452, 459989, 507322
17+ * Stefan Winkler <stefan@winklerweb.net> - Bug #3742
1718 *******************************************************************************/
1819package org .eclipse .ui .internal .quickaccess ;
1920
5758import org .eclipse .swt .events .ControlEvent ;
5859import org .eclipse .swt .events .KeyEvent ;
5960import org .eclipse .swt .events .KeyListener ;
60- import org .eclipse .swt .events .MouseAdapter ;
6161import org .eclipse .swt .events .MouseEvent ;
62+ import org .eclipse .swt .events .MouseListener ;
6263import org .eclipse .swt .events .MouseMoveListener ;
63- import org .eclipse .swt .events .SelectionAdapter ;
64- import org .eclipse .swt .events .SelectionEvent ;
64+ import org .eclipse .swt .events .SelectionListener ;
6565import org .eclipse .swt .graphics .Color ;
6666import org .eclipse .swt .graphics .Font ;
6767import org .eclipse .swt .graphics .Point ;
@@ -105,6 +105,7 @@ public abstract class QuickAccessContents {
105105 private Map <String , QuickAccessProvider > providerMap = new HashMap <>();
106106 private final Map <QuickAccessElement , QuickAccessProvider > elementsToProviders = new HashMap <>();
107107
108+ private Composite tableComposite ;
108109 protected Table table ;
109110 protected Label infoLabel ;
110111
@@ -723,37 +724,18 @@ private void setHintTextToDisplay(boolean toDisplay) {
723724 }
724725
725726 /**
726- * Creates the table providing the contents for the quick access dialog
727+ * Creates the table providing the contents for the quick access dialog. After
728+ * applying the dialog font, call {@link #installTableStyling(int)} to complete
729+ * the styling and layout for this table.
727730 *
728- * @param composite parent composite with {@link GridLayout}
729- * @param defaultOrientation the window orientation to use for the table
730- * {@link SWT#RIGHT_TO_LEFT} or
731- * {@link SWT#LEFT_TO_RIGHT}
731+ * @param composite parent composite with {@link GridLayout}
732732 * @return the created table
733733 */
734- public Table createTable (Composite composite , int defaultOrientation ) {
734+ public Table createTable (Composite composite ) {
735735 composite .addDisposeListener (e -> doDispose ());
736- Composite tableComposite = new Composite (composite , SWT .NONE );
736+ tableComposite = new Composite (composite , SWT .NONE );
737737 GridDataFactory .fillDefaults ().grab (true , true ).applyTo (tableComposite );
738- TableColumnLayout tableColumnLayout = new TableColumnLayout ();
739- tableComposite .setLayout (tableColumnLayout );
740738 table = new Table (tableComposite , SWT .SINGLE | SWT .FULL_SELECTION );
741- textLayout = new TextLayout (table .getDisplay ());
742- textLayout .setOrientation (defaultOrientation );
743- Font boldFont = resourceManager .create (FontDescriptor .createFrom (table .getFont ()).setStyle (SWT .BOLD ));
744- textLayout .setFont (table .getFont ());
745- textLayout .setText (QuickAccessMessages .QuickAccess_AvailableCategories );
746- int maxProviderWidth = (textLayout .getBounds ().width );
747- textLayout .setFont (boldFont );
748- for (QuickAccessProvider provider : providers ) {
749- textLayout .setText (provider .getName ());
750- int width = (textLayout .getBounds ().width );
751- if (width > maxProviderWidth ) {
752- maxProviderWidth = width ;
753- }
754- }
755- tableColumnLayout .setColumnData (new TableColumn (table , SWT .NONE ), new ColumnWeightData (0 , maxProviderWidth ));
756- tableColumnLayout .setColumnData (new TableColumn (table , SWT .NONE ), new ColumnWeightData (100 , 100 ));
757739 table .getShell ().addControlListener (new ControlAdapter () {
758740 @ Override
759741 public void controlResized (ControlEvent e ) {
@@ -772,42 +754,31 @@ public void controlResized(ControlEvent e) {
772754 }
773755 });
774756
775- table .addKeyListener (new KeyListener () {
776- @ Override
777- public void keyPressed (KeyEvent e ) {
778- if (e .keyCode == SWT .ARROW_UP && table .getSelectionIndex () == 0 ) {
779- filterText .setFocus ();
780- } else if (e .character == SWT .ESC ) {
781- doClose ();
782- }
757+ table .addKeyListener (KeyListener .keyPressedAdapter (e -> {
758+ if (e .keyCode == SWT .ARROW_UP && table .getSelectionIndex () == 0 ) {
759+ filterText .setFocus ();
760+ } else if (e .character == SWT .ESC ) {
761+ doClose ();
783762 }
763+ }));
784764
785- @ Override
786- public void keyReleased ( KeyEvent e ) {
787- // do nothing
765+ table . addMouseListener ( MouseListener . mouseUpAdapter ( e -> {
766+ if ( table . getSelectionCount () < 1 ) {
767+ return ;
788768 }
789- });
790- table .addMouseListener (new MouseAdapter () {
791- @ Override
792- public void mouseUp (MouseEvent e ) {
793-
794- if (table .getSelectionCount () < 1 ) {
795- return ;
796- }
797769
798- if (e .button != 1 ) {
799- return ;
800- }
770+ if (e .button != 1 ) {
771+ return ;
772+ }
801773
802- if (table .equals (e .getSource ())) {
803- Object o = table .getItem (new Point (e .x , e .y ));
804- TableItem selection = table .getSelection ()[0 ];
805- if (selection .equals (o )) {
806- handleSelection ();
807- }
774+ if (table .equals (e .getSource ())) {
775+ Object o = table .getItem (new Point (e .x , e .y ));
776+ TableItem selection = table .getSelection ()[0 ];
777+ if (selection .equals (o )) {
778+ handleSelection ();
808779 }
809780 }
810- });
781+ })) ;
811782
812783 table .addMouseMoveListener (new MouseMoveListener () {
813784 TableItem lastItem = null ;
@@ -831,13 +802,44 @@ public void mouseMove(MouseEvent e) {
831802 }
832803 });
833804
834- table .addSelectionListener (new SelectionAdapter () {
835- @ Override
836- public void widgetDefaultSelected (SelectionEvent e ) {
837- handleSelection ();
805+ table .addSelectionListener (SelectionListener .widgetDefaultSelectedAdapter (e -> handleSelection ()));
806+ return table ;
807+ }
808+
809+ /**
810+ * Complete the styling/layout for the table.
811+ *
812+ * This method must be called after {@link #createTable(Composite)} and after
813+ * the containing dialog implementation has applied the dialog fonts.
814+ *
815+ * @param defaultOrientation the window orientation to use for the table
816+ * {@link SWT#RIGHT_TO_LEFT} or
817+ * {@link SWT#LEFT_TO_RIGHT}
818+ */
819+ public void configureTableStyling (int defaultOrientation ) {
820+ // configure the text layout
821+ textLayout = new TextLayout (table .getDisplay ());
822+ textLayout .setOrientation (defaultOrientation );
823+ Font boldFont = resourceManager .create (FontDescriptor .createFrom (table .getFont ()).setStyle (SWT .BOLD ));
824+ textLayout .setFont (table .getFont ());
825+ textLayout .setText (QuickAccessMessages .QuickAccess_AvailableCategories );
826+ int maxProviderWidth = (textLayout .getBounds ().width );
827+ textLayout .setFont (boldFont );
828+ for (QuickAccessProvider provider : providers ) {
829+ textLayout .setText (provider .getName ());
830+ int width = (textLayout .getBounds ().width );
831+ if (width > maxProviderWidth ) {
832+ maxProviderWidth = width ;
838833 }
839- });
834+ }
835+
836+ // configure the table layout
837+ TableColumnLayout tableColumnLayout = new TableColumnLayout ();
838+ tableComposite .setLayout (tableColumnLayout );
839+ tableColumnLayout .setColumnData (new TableColumn (table , SWT .NONE ), new ColumnWeightData (0 , maxProviderWidth ));
840+ tableColumnLayout .setColumnData (new TableColumn (table , SWT .NONE ), new ColumnWeightData (100 , 100 ));
840841
842+ // configure listeners
841843 final TextStyle boldStyle ;
842844 if (PlatformUI .getPreferenceStore ().getBoolean (IWorkbenchPreferenceConstants .USE_COLORED_LABELS )) {
843845 boldStyle = new TextStyle (boldFont , null , null );
@@ -865,8 +867,6 @@ public void widgetDefaultSelected(SelectionEvent e) {
865867 table .addListener (SWT .MeasureItem , listener );
866868 table .addListener (SWT .EraseItem , listener );
867869 table .addListener (SWT .PaintItem , listener );
868-
869- return table ;
870870 }
871871
872872 /**
0 commit comments