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