Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse toolbar #421

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feature: Convert the Eclipse status bar widget into a menu contribution
  • Loading branch information
gtoison committed Oct 20, 2024
commit 4af07f261141fd89f9ae6239cc14fef5c4580427
20 changes: 6 additions & 14 deletions infinitest-eclipse/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,11 @@
</super>
</extension>
<extension point="org.eclipse.ui.menus">
<group id="org.infinitest.eclipse.trimwidget" separatorsVisible="true">
<location>
<bar type="trim">
</bar>
<order position="before" relativeTo="status">
</order>
</location>
</group>
<widget class="org.infinitest.eclipse.trim.StatusBar" id="org.infinitest.eclipse.trim.status">
<location>
<bar path="org.infinitest.eclipse.trimwidget" type="trim">
</bar>
</location>
</widget>
<menuContribution allPopups="false" locationURI="toolbar:org.eclipse.ui.trim.status">
<toolbar id="org.infinitest.eclipse.status" label="Infinitest Bar">
<control id="org.infinitest.eclipse.trim.StatusBar" class="org.infinitest.eclipse.trim.StatusBar">
</control>
</toolbar>
</menuContribution>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,24 @@
*/
package org.infinitest.eclipse.trim;

import static org.eclipse.swt.SWT.*;
import static org.infinitest.eclipse.util.GraphicsUtils.*;
import static org.eclipse.swt.SWT.BORDER;
import static org.eclipse.swt.SWT.COLOR_BLACK;
import static org.eclipse.swt.SWT.COLOR_WHITE;
import static org.eclipse.swt.SWT.LEFT;
import static org.eclipse.swt.SWT.NONE;
import static org.infinitest.eclipse.util.GraphicsUtils.getColor;

import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.menus.*;
import org.infinitest.eclipse.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
import org.infinitest.eclipse.InfinitestPlugin;
import org.infinitest.eclipse.PluginActivationController;

public class StatusBar extends AbstractWorkbenchTrimWidget implements VisualStatus {
public class StatusBar extends WorkbenchWindowControlContribution implements VisualStatus {

/**
* Cache the current trim so we can 'dispose' it on demand
*/
Expand All @@ -45,8 +53,13 @@ public class StatusBar extends AbstractWorkbenchTrimWidget implements VisualStat
private String statusString = "Infinitest is waiting for changes";
private int backgroundColor = COLOR_BLACK;

@Override
public void init(IWorkbenchWindow workbenchWindow) {
public StatusBar() {
getPluginController().attachVisualStatus(this);
}

public StatusBar(String id) {
super(id);

getPluginController().attachVisualStatus(this);
}

Expand All @@ -57,35 +70,29 @@ public void dispose() {
}
composite = null;
}

@Override
public void fill(Composite parent, int oldSide, int newSide) {

protected Control createControl(Composite parent) {
// See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=471313#c12
parent.getParent().setRedraw(true);

composite = new Composite(parent, NONE);

RowLayout layout = new RowLayout();
layout.marginHeight = 4;
layout.marginWidth = 2;
layout.center = true;

FillLayout layout = new FillLayout();
composite.setLayout(layout);

addStatusLabel(newSide);
composite.layout();
}

private void addStatusLabel(int newSide) {

statusLabel = new Label(composite, BORDER | LEFT);
statusLabel.setLayoutData(getRowData(newSide));
statusLabel.setForeground(getColor(COLOR_WHITE));
statusLabel.setText(statusString);
statusLabel.setBackground(getColor(backgroundColor));

return composite;
}

RowData getRowData(int newSide) {
RowData rowData = new RowData();
if ((newSide == BOTTOM) || (newSide == TOP)) {
rowData.width = 400;
}
return rowData;

@Override
public boolean isDynamic() {
// See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=471313#c12
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,13 @@
*/
package org.infinitest.eclipse.trim;

import static org.eclipse.swt.SWT.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.eclipse.swt.layout.*;
import org.infinitest.eclipse.*;
import org.junit.jupiter.api.BeforeEach;
import org.infinitest.eclipse.PluginActivationController;
import org.junit.jupiter.api.Test;

class StatusBarTest {
private StatusBar statusBar;

@BeforeEach
void inContext() {
statusBar = new StatusBar();
}

@Test
void shouldShrinkWhenMovedToSideBars() {
RowData rowData = statusBar.getRowData(BOTTOM);
assertEquals(400, rowData.width);

rowData = statusBar.getRowData(LEFT);
assertEquals(-1, rowData.width);
}

@Test
void shouldRegisterStatusPluginController() {
Expand All @@ -62,7 +44,6 @@ protected PluginActivationController getPluginController() {
return mockController;
}
};
statusBar.init(null);

verify(mockController).attachVisualStatus(statusBar);
}
Expand Down
Loading