Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 472654, 491272, 491398
* Leung Wang Hei <gemaspecial@yahoo.com.hk> - Bug 483343
* Patrik Suzzi <psuzzi@gmail.com> - Bug 491291, 491529, 491293, 492434, 492452, 459989, 507322
* Stefan Winkler <stefan@winklerweb.net> - Bug #3742
*******************************************************************************/
package org.eclipse.ui.internal.quickaccess;

Expand Down Expand Up @@ -57,11 +58,10 @@
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -105,6 +105,7 @@
private Map<String, QuickAccessProvider> providerMap = new HashMap<>();
private final Map<QuickAccessElement, QuickAccessProvider> elementsToProviders = new HashMap<>();

private Composite tableComposite;
protected Table table;
protected Label infoLabel;

Expand Down Expand Up @@ -723,37 +724,18 @@
}

/**
* Creates the table providing the contents for the quick access dialog
* Creates the table providing the contents for the quick access dialog. After
* applying the dialog font, call {@link #installTableStyling(int)} to complete

Check warning on line 728 in bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Javadoc

NORMAL: Javadoc: The method installTableStyling(int) is undefined for the type QuickAccessContents
* the styling and layout for this table.
*
* @param composite parent composite with {@link GridLayout}
* @param defaultOrientation the window orientation to use for the table
* {@link SWT#RIGHT_TO_LEFT} or
* {@link SWT#LEFT_TO_RIGHT}
* @param composite parent composite with {@link GridLayout}
* @return the created table
*/
public Table createTable(Composite composite, int defaultOrientation) {
public Table createTable(Composite composite) {
composite.addDisposeListener(e -> doDispose());
Composite tableComposite = new Composite(composite, SWT.NONE);
tableComposite = new Composite(composite, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);
TableColumnLayout tableColumnLayout = new TableColumnLayout();
tableComposite.setLayout(tableColumnLayout);
table = new Table(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION);
textLayout = new TextLayout(table.getDisplay());
textLayout.setOrientation(defaultOrientation);
Font boldFont = resourceManager.create(FontDescriptor.createFrom(table.getFont()).setStyle(SWT.BOLD));
textLayout.setFont(table.getFont());
textLayout.setText(QuickAccessMessages.QuickAccess_AvailableCategories);
int maxProviderWidth = (textLayout.getBounds().width);
textLayout.setFont(boldFont);
for (QuickAccessProvider provider : providers) {
textLayout.setText(provider.getName());
int width = (textLayout.getBounds().width);
if (width > maxProviderWidth) {
maxProviderWidth = width;
}
}
tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(0, maxProviderWidth));
tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(100, 100));
table.getShell().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Expand All @@ -772,42 +754,31 @@
}
});

table.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_UP && table.getSelectionIndex() == 0) {
filterText.setFocus();
} else if (e.character == SWT.ESC) {
doClose();
}
table.addKeyListener(KeyListener.keyPressedAdapter(e -> {
if (e.keyCode == SWT.ARROW_UP && table.getSelectionIndex() == 0) {
filterText.setFocus();
} else if (e.character == SWT.ESC) {
doClose();
}
}));

@Override
public void keyReleased(KeyEvent e) {
// do nothing
table.addMouseListener(MouseListener.mouseUpAdapter(e -> {
if (table.getSelectionCount() < 1) {
return;
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {

if (table.getSelectionCount() < 1) {
return;
}

if (e.button != 1) {
return;
}
if (e.button != 1) {
return;
}

if (table.equals(e.getSource())) {
Object o = table.getItem(new Point(e.x, e.y));
TableItem selection = table.getSelection()[0];
if (selection.equals(o)) {
handleSelection();
}
if (table.equals(e.getSource())) {
Object o = table.getItem(new Point(e.x, e.y));
TableItem selection = table.getSelection()[0];
if (selection.equals(o)) {
handleSelection();
}
}
});
}));

table.addMouseMoveListener(new MouseMoveListener() {
TableItem lastItem = null;
Expand All @@ -831,13 +802,44 @@
}
});

table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
handleSelection();
table.addSelectionListener(SelectionListener.widgetDefaultSelectedAdapter(e -> handleSelection()));
return table;
}

/**
* Complete the styling/layout for the table.
*
* This method must be called after {@link #createTable(Composite)} and after
* the containing dialog implementation has applied the dialog fonts.
*
* @param defaultOrientation the window orientation to use for the table
* {@link SWT#RIGHT_TO_LEFT} or
* {@link SWT#LEFT_TO_RIGHT}
*/
public void configureTableStyling(int defaultOrientation) {
// configure the text layout
textLayout = new TextLayout(table.getDisplay());
textLayout.setOrientation(defaultOrientation);
Font boldFont = resourceManager.create(FontDescriptor.createFrom(table.getFont()).setStyle(SWT.BOLD));
textLayout.setFont(table.getFont());
textLayout.setText(QuickAccessMessages.QuickAccess_AvailableCategories);
int maxProviderWidth = (textLayout.getBounds().width);
textLayout.setFont(boldFont);
for (QuickAccessProvider provider : providers) {
textLayout.setText(provider.getName());
int width = (textLayout.getBounds().width);
if (width > maxProviderWidth) {
maxProviderWidth = width;
}
});
}

// configure the table layout
TableColumnLayout tableColumnLayout = new TableColumnLayout();
tableComposite.setLayout(tableColumnLayout);
tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(0, maxProviderWidth));
tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(100, 100));

// configure listeners
final TextStyle boldStyle;
if (PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)) {
boldStyle = new TextStyle(boldFont, null, null);
Expand Down Expand Up @@ -865,8 +867,6 @@
table.addListener(SWT.MeasureItem, listener);
table.addListener(SWT.EraseItem, listener);
table.addListener(SWT.PaintItem, listener);

return table;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Tom Hochstein (Freescale) - Bug 393703 - NotHandledException selecting inactive command under 'Previous Choices' in Quick access
* René Brandstetter - Bug 433778
* Patrik Suzzi <psuzzi@gmail.com> - Bug 491410
* Stefan Winkler <stefan@winklerweb.net> - Bug #3742
*******************************************************************************/
package org.eclipse.ui.internal.quickaccess;

Expand Down Expand Up @@ -246,12 +247,23 @@ protected Control createDialogArea(Composite parent) {
gridData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
hintText.setLayoutData(gridData);

Table table = contents.createTable(composite, getDefaultOrientation());
Table table = contents.createTable(composite);
table.addKeyListener(getKeyAdapter());

return composite;
}

@Override
protected Control createContents(Composite parent) {
Control control = super.createContents(parent);

// after the complete contents (including dialog fonts) are configured, apply
// the table layout and styling
contents.configureTableStyling(getDefaultOrientation());

return control;
}

private TriggerSequence[] getInvokingCommandKeySequences() {
if (invokingCommandKeySequences == null) {
if (invokingCommand != null) {
Expand Down Expand Up @@ -309,6 +321,7 @@ public boolean close() {
@Override
protected Point getDefaultSize() {
GC gc = new GC(getContents());
gc.setFont(contents.getTable().getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
int x = Dialog.convertHorizontalDLUsToPixels(fontMetrics, 300);
Expand Down
Loading