Skip to content

Commit

Permalink
Path combo, fullscreen menu button
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaustein committed Feb 27, 2017
1 parent 8969c30 commit 01a53ad
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 46 deletions.
Expand Up @@ -11,6 +11,7 @@
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
Expand All @@ -25,6 +26,7 @@
import org.flowgrid.swt.graphics.ArtifactIcon;

import java.io.IOException;
import java.util.ArrayList;

public class OpenArtifactDialog {
final SwtFlowgrid flowgrid;
Expand All @@ -33,17 +35,34 @@ public class OpenArtifactDialog {
final Table table;
AlertDialog alertDialog;
Module module;
final Composite pathComposite;
final Combo pathCombo;
final SelectionListener pathSelectionListener;

OpenArtifactDialog(final SwtFlowgrid flowgrid, Module initialModule) {
this.flowgrid = flowgrid;
this.module = initialModule;
alertDialog = new AlertDialog(flowgrid.shell);

RowLayout pathLayout = new RowLayout();
pathLayout.spacing = 0;
pathComposite = new Composite(alertDialog.getContentContainer(), SWT.NONE);
pathComposite.setLayout(pathLayout);
pathCombo = new Combo(alertDialog.getContentContainer(), SWT.DROP_DOWN);
pathSelectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
int up = pathCombo.getItemCount() - 1 - pathCombo.getSelectionIndex();
System.out.println("itemCount: " + pathCombo.getItemCount() + " sel idx: " + pathCombo.getSelectionIndex() + " up: " + up + " current: " + module);
Module current = module;
while (up > 0 && current.parent() != null){
current = current.parent();
up--;
}
setModule(current);
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
};

table = new Table(alertDialog.getContentContainer(), SWT.NONE);
GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
Expand All @@ -52,7 +71,6 @@ public class OpenArtifactDialog {

tableGridData.minimumHeight = shellSize.y / 2;
table.setLayoutData(tableGridData);
setModule(module);

alertDialog.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
@Override
Expand Down Expand Up @@ -95,58 +113,35 @@ public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});

setModule(initialModule);
}

void show() {
alertDialog.show();
}

int addPath(final Module module, int topDistance) {
if (module == null) {
return 0;
}
int rootDistance = addPath(module.parent(), topDistance + 1);
if (rootDistance < 2 || topDistance < 2) {
Label label = new Label(pathComposite, SWT.NONE);
label.setData(module);
label.setText(module.parent() == null ? "root" : module.name());
if (topDistance != 0) {
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
setModule(module);
}
});
new Label(pathComposite, SWT.NONE).setText(" > ");
}
} else if (topDistance == 2) {
new Label(pathComposite, SWT.NONE).setText("... > ");
}
return rootDistance + 1;
}

void setModule(Module module) {
if (module == this.module) {
return;
}
this.module = module;
alertDialog.setTitle("Open / Create");

for (Control part : pathComposite.getChildren()) {
part.dispose();
}

addPath(module, 0);
pathCombo.removeSelectionListener(pathSelectionListener);
pathCombo.removeAll();
Module current = module;
do {
String name = current.name();
pathCombo.add(name.isEmpty() ? "<root>" : name, 0);
current = current.parent();
} while (current != null);
pathCombo.select(pathCombo.getItemCount() - 1);
pathCombo.addSelectionListener(pathSelectionListener);

table.removeAll();

/*
if (module.parent() != null) {
TableItem backItem = new TableItem(table, SWT.NONE);
backItem.setText(0, module.parent().parent() == null ? "(root)" : module.parent().name());
// ArtifactComposite artifactComposite = new ArtifactComposite(list, flowgrid.resourceManager, module.parent(), true);
// artifactComposite.setListener(callback);
backItem.setData(module.parent());
}
*/

int iconSize = flowgrid.resourceManager.dpToPx(24);
for (final Artifact artifact: module) {
if (!artifact.isBuiltin()) {
Expand Down
Expand Up @@ -121,6 +121,7 @@ public class OperationCanvas extends Canvas implements ContextMenu.ItemClickList

Button resetButton;
Button startPauseButton;
Button moreButton;

Button fasterButton;
Button slowerButton;
Expand Down Expand Up @@ -215,6 +216,26 @@ public void widgetSelected(SelectionEvent e) {
resetButton = new Button(this, SWT.PUSH);
resetButton.setImage(flowgrid.resourceManager.getIcon(ResourceManager.Icon.STOP));
resetButton.addSelectionListener(resetListener);

if (operationEditor.fullScreen) {
moreButton = new Button(this, SWT.PUSH);
moreButton.setImage(flowgrid.resourceManager.getIcon(ResourceManager.Icon.MORE_VERT));
moreButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
Menu menu = new Menu(flowgrid.shell());
operationEditor.fillMenuImpl(menu);
menu.setLocation(moreButton.toDisplay(0, moreButton.getSize().y));
menu.setVisible(true);
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
}

}

menuAnchor = new Label(this, SWT.NONE);
Expand Down Expand Up @@ -468,7 +489,8 @@ protected void layout(Composite composite, boolean flushCache) {
int spacing = 5;

if (startPauseButton != null) {
Button[] topButtons = new Button[]{startPauseButton, resetButton};
Button[] topButtons = moreButton == null ? new Button[]{startPauseButton, resetButton}
: new Button[]{startPauseButton, resetButton, moreButton};

int buttonW = 0;
int buttonH = 0;
Expand Down
Expand Up @@ -89,11 +89,13 @@ static String portType(HutnObject peerJson) {
boolean running;
ScrolledComposite scrolledComposite;
Timer timer;
boolean fullScreen;


public OperationEditor(final SwtFlowgrid flowgrid, final CustomOperation operation, boolean addTitle) {
this.flowgrid = flowgrid;
this.operation = operation;
this.fullScreen = addTitle;

tutorialMode = operation.isTutorial();

Expand Down Expand Up @@ -165,8 +167,6 @@ public void widgetDefaultSelected(SelectionEvent e) {
controlLayout.marginWidth = 0;
controlPanel.setLayout(controlLayout);



scrolledComposite.setContent(controlPanel);

controller.setVisual(true);
Expand Down Expand Up @@ -633,6 +633,12 @@ public void run() {
}

public void fillMenu(Menu menu) {
if (!fullScreen) {
fillMenuImpl(menu);
}
}

public void fillMenuImpl(Menu menu) {
ContextMenu operationMenu = new ContextMenu(menu);
operationMenu.setOnMenuItemClickListener(this);

Expand Down

0 comments on commit 01a53ad

Please sign in to comment.