]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/QueryArtifactsText.java
c73dcbecacd4009d5a83f50f3257e955727d572a
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / views / QueryArtifactsText.java
1 package org.argeo.slc.client.ui.dist.views;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.argeo.slc.client.ui.dist.DistPlugin;
6 import org.argeo.slc.jcr.SlcNames;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.custom.SashForm;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Event;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Listener;
16 import org.eclipse.swt.widgets.Text;
17
18 /** Query SLC Repo to get some artifacts with a JCR SQL 2 request. */
19 public class QueryArtifactsText extends AbstractQueryArtifactsView implements
20 SlcNames {
21 private static final Log log = LogFactory.getLog(QueryArtifactsText.class);
22 public static final String ID = DistPlugin.ID + ".queryArtifactsText";
23
24 // widgets
25 private Button executeBtn;
26 private Text queryText;
27 private SashForm sashForm;
28
29 private Composite top, bottom;
30
31 @Override
32 public void createPartControl(Composite parent) {
33
34 sashForm = new SashForm(parent, SWT.VERTICAL);
35 sashForm.setSashWidth(4);
36 sashForm.setLayout(new GridLayout(1, false));
37
38 top = new Composite(sashForm, SWT.NONE);
39 top.setLayout(new GridLayout(1, false));
40
41 bottom = new Composite(sashForm, SWT.NONE);
42 bottom.setLayout(new GridLayout(1, false));
43
44 sashForm.setWeights(new int[] { 25, 75 });
45
46 createQueryForm(top);
47 createResultPart(bottom);
48 }
49
50 public void createQueryForm(Composite parent) {
51 Label lbl;
52 GridData gd;
53
54 GridLayout gl = new GridLayout(2, false);
55 gl.marginTop = 5;
56 parent.setLayout(gl);
57
58 lbl = new Label(parent, SWT.SINGLE);
59 lbl.setText("Enter a JCR:SQL2 Query");
60
61 executeBtn = new Button(parent, SWT.PUSH);
62 executeBtn.setText("Search");
63
64 queryText = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER);
65 gd = new GridData(GridData.FILL_HORIZONTAL);
66 gd.grabExcessHorizontalSpace = true;
67 gd.heightHint = 100;
68 gd.horizontalSpan = 2;
69 queryText.setLayoutData(gd);
70
71 String query = generateSelectStatement() + generateFromStatement()
72 + generateWhereStatement();
73 queryText.setText(query);
74
75 Listener executeListener = new Listener() {
76 public void handleEvent(Event event) {
77 refreshQuery();
78 }
79 };
80 executeBtn.addListener(SWT.Selection, executeListener);
81 }
82
83 public void refreshQuery() {
84 String queryStr = queryText.getText();
85 executeQuery(queryStr);
86 bottom.layout();
87 sashForm.layout();
88 }
89
90 private String generateWhereStatement() {
91 StringBuffer sb = new StringBuffer(" where ");
92 return sb.toString();
93 }
94
95 @Override
96 public void setFocus() {
97 executeBtn.setFocus();
98 }
99 }