/
TriggerTableLayout.java
115 lines (88 loc) · 3.94 KB
/
TriggerTableLayout.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package org.jumpmind.vaadin.ui.sqlexplorer;
import java.util.Map;
import org.jumpmind.db.model.Trigger;
import org.jumpmind.vaadin.ui.common.ReadOnlyTextAreaDialog;
import org.jumpmind.vaadin.ui.sqlexplorer.TriggerInfoPanel.Refresher;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.shared.MouseEventDetails.MouseButton;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
public class TriggerTableLayout extends VerticalLayout{
private static final long serialVersionUID = 1L;
private Trigger trigger;
private Grid<String> grid;
private Refresher refresher;
public TriggerTableLayout(Trigger trigger, Settings settings, Refresher refresher) {
this.trigger = trigger;
this.refresher = refresher;
createTabularLayout();
}
public void createTabularLayout() {
this.setSizeFull();
this.setSpacing(false);
HorizontalLayout bar = new HorizontalLayout();
bar.setWidth(100, Unit.PERCENTAGE);
bar.setMargin(new MarginInfo(false, true, false, true));
HorizontalLayout leftBar = new HorizontalLayout();
leftBar.setSpacing(true);
final Label label = new Label(trigger.getFullyQualifiedName(), ContentMode.HTML);
leftBar.addComponent(label);
bar.addComponent(leftBar);
bar.setComponentAlignment(leftBar, Alignment.MIDDLE_LEFT);
bar.setExpandRatio(leftBar, 1);
MenuBar rightBar = new MenuBar();
rightBar.addStyleName(ValoTheme.MENUBAR_BORDERLESS);
rightBar.addStyleName(ValoTheme.MENUBAR_SMALL);
MenuItem refreshButton = rightBar.addItem("", new Command() {
private static final long serialVersionUID = 1L;
@Override
public void menuSelected(MenuItem selectedItem) {
refresher.refresh();
}
});
refreshButton.setIcon(VaadinIcons.REFRESH);
bar.addComponent(rightBar);
bar.setComponentAlignment(rightBar, Alignment.MIDDLE_RIGHT);
this.addComponent(bar);
grid = fillGrid();
grid.setSizeFull();
grid.addItemClickListener(event -> {
MouseButton button = event.getMouseEventDetails().getButton();
if (button == MouseButton.LEFT && event.getColumn() != null) {
if (event.getMouseEventDetails().isDoubleClick()) {
String colId = event.getColumn().getId();
if (colId.equals("property")) {
ReadOnlyTextAreaDialog.show("Property", event.getItem(), false);
} else if (colId.equals("value")) {
ReadOnlyTextAreaDialog.show("Value", (String) trigger.getMetaData().get(event.getItem()), false);
}
} else {
grid.deselectAll();
grid.select(event.getItem());
}
}
});
this.addComponent(grid);
this.setExpandRatio(grid, 1);
}
private Grid<String> fillGrid() {
Grid<String> grid = new Grid<String>();
grid.setSelectionMode(SelectionMode.MULTI);
grid.setColumnReorderingAllowed(false);
Map<String, Object> metaData = trigger.getMetaData();
grid.addColumn(property -> property).setId("property").setCaption("Property").setWidth(250);
grid.addColumn(property -> String.valueOf(metaData.get(property))).setId("value").setCaption("Value");
grid.setItems(metaData.keySet());
return grid;
}
}