1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.connect.ui.parts;
17
18 import javax.jcr.Node;
19 import javax.jcr.Session;
20
21 import org.argeo.connect.ConnectTypes;
22 import org.argeo.connect.ui.AppWorkbenchService;
23 import org.argeo.eclipse.ui.EclipseUiUtils;
24 import org.eclipse.jface.dialogs.TrayDialog;
25 import org.eclipse.jface.viewers.DoubleClickEvent;
26 import org.eclipse.jface.viewers.IDoubleClickListener;
27 import org.eclipse.jface.viewers.ISelectionChangedListener;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.jface.viewers.SelectionChangedEvent;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.graphics.Point;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Button;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Control;
36 import org.eclipse.swt.widgets.Shell;
37
38
39
40
41
42 public class PickUpRelatedDialog extends TrayDialog {
43 private static final long serialVersionUID = -2526572299370624808L;
44
45
46 private final Session session;
47 private final AppWorkbenchService appWorkbenchService;
48 private Node selectedNode;
49
50
51 private FilterEntitiesVirtualTable tableCmp;
52 private final String title;
53
54
55 private Button dummyButton;
56
57 public PickUpRelatedDialog(Shell parentShell, String title, Session session,
58 AppWorkbenchService appWorkbenchService, Node referencingNode) {
59 super(parentShell);
60 this.title = title;
61
62 this.session = session;
63 this.appWorkbenchService = appWorkbenchService;
64 }
65
66 protected Point getInitialSize() {
67 return new Point(400, 600);
68 }
69
70 protected Control createDialogArea(Composite parent) {
71 Composite dialogArea = (Composite) super.createDialogArea(parent);
72
73
74
75
76 Composite bodyCmp = new Composite(dialogArea, SWT.NO_FOCUS);
77 bodyCmp.setLayoutData(EclipseUiUtils.fillAll());
78 bodyCmp.setLayout(new GridLayout());
79
80 int style = SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL;
81 tableCmp = new FilterEntitiesVirtualTable(bodyCmp, style, session, appWorkbenchService,
82 ConnectTypes.CONNECT_ENTITY);
83 tableCmp.setLayoutData(EclipseUiUtils.fillAll());
84 tableCmp.getTableViewer().addDoubleClickListener(new MyDoubleClickListener());
85 tableCmp.getTableViewer().addSelectionChangedListener(new MySelectionChangedListener());
86
87
88 dummyButton = new Button(dialogArea, SWT.PUSH);
89 dummyButton.setVisible(false);
90
91 parent.pack();
92 return dialogArea;
93 }
94
95 public Node getSelected() {
96 return selectedNode;
97 }
98
99 protected void configureShell(Shell shell) {
100 super.configureShell(shell);
101 shell.setText(title);
102 }
103
104 @Override
105 public void create() {
106 super.create();
107 getShell().setDefaultButton(dummyButton);
108 }
109
110 class MySelectionChangedListener implements ISelectionChangedListener {
111 @Override
112 public void selectionChanged(SelectionChangedEvent event) {
113 if (event.getSelection().isEmpty())
114 return;
115
116 Object obj = ((IStructuredSelection) event.getSelection()).getFirstElement();
117 if (obj instanceof Node) {
118 selectedNode = (Node) obj;
119 }
120 }
121 }
122
123 class MyDoubleClickListener implements IDoubleClickListener {
124 public void doubleClick(DoubleClickEvent evt) {
125 if (evt.getSelection().isEmpty())
126 return;
127
128 Object obj = ((IStructuredSelection) evt.getSelection()).getFirstElement();
129 if (obj instanceof Node) {
130 selectedNode = (Node) obj;
131 okPressed();
132 }
133 }
134 }
135 }