]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/views/QueryArtifactsText.java
Adapt to changes in BND.
[gpl/argeo-slc.git] / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / views / QueryArtifactsText.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.client.ui.dist.views;
17
18 import org.argeo.slc.SlcNames;
19 import org.argeo.slc.client.ui.dist.DistPlugin;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.custom.SashForm;
22 import org.eclipse.swt.layout.FillLayout;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Event;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Listener;
30 import org.eclipse.swt.widgets.Text;
31
32 /** Query SLC Repo to get some artifacts with a JCR SQL 2 request. */
33 public class QueryArtifactsText extends AbstractQueryArtifactsView implements
34 SlcNames {
35 // private static final Log log =
36 // LogFactory.getLog(QueryArtifactsText.class);
37 public static final String ID = DistPlugin.PLUGIN_ID + ".queryArtifactsText";
38
39 // widgets
40 private Button executeBtn;
41 private Text queryText;
42 private SashForm sashForm;
43
44 private Composite top, bottom;
45
46 @Override
47 public void createPartControl(Composite parent) {
48
49 sashForm = new SashForm(parent, SWT.VERTICAL);
50 sashForm.setSashWidth(4);
51 // Enable the different parts to fill the whole page when the tab is
52 // maximized
53 sashForm.setLayout(new FillLayout());
54
55 top = new Composite(sashForm, SWT.NONE);
56 top.setLayout(new GridLayout(1, false));
57
58 bottom = new Composite(sashForm, SWT.NONE);
59 bottom.setLayout(new GridLayout(1, false));
60
61 sashForm.setWeights(new int[] { 25, 75 });
62
63 createQueryForm(top);
64 createResultPart(bottom);
65 }
66
67 public void createQueryForm(Composite parent) {
68 Label lbl;
69 GridData gd;
70
71 GridLayout gl = new GridLayout(2, false);
72 gl.marginTop = 5;
73 parent.setLayout(gl);
74
75 lbl = new Label(parent, SWT.SINGLE);
76 lbl.setText("Enter a JCR:SQL2 Query");
77
78 executeBtn = new Button(parent, SWT.PUSH);
79 executeBtn.setText("Search");
80
81 queryText = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER);
82 gd = new GridData(GridData.FILL_HORIZONTAL);
83 gd.grabExcessHorizontalSpace = true;
84 gd.heightHint = 100;
85 gd.horizontalSpan = 2;
86 queryText.setLayoutData(gd);
87
88 String query = generateSelectStatement() + generateFromStatement()
89 + generateWhereStatement();
90 queryText.setText(query);
91
92 Listener executeListener = new Listener() {
93 private static final long serialVersionUID = -5028331930076117569L;
94
95 public void handleEvent(Event event) {
96 refreshQuery();
97 }
98 };
99 executeBtn.addListener(SWT.Selection, executeListener);
100 }
101
102 public void refreshQuery() {
103 String queryStr = queryText.getText();
104 executeQuery(queryStr);
105 bottom.layout();
106 sashForm.layout();
107 }
108
109 private String generateWhereStatement() {
110 StringBuffer sb = new StringBuffer(" where ");
111 return sb.toString();
112 }
113
114 @Override
115 public void setFocus() {
116 executeBtn.setFocus();
117 }
118 }