2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.client
.ui
.dist
.views
;
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
;
34 /** Query SLC Repo to get some artifacts with a JCR SQL 2 request. */
35 public class QueryArtifactsText
extends AbstractQueryArtifactsView
implements
37 private static final Log log
= LogFactory
.getLog(QueryArtifactsText
.class);
38 public static final String ID
= DistPlugin
.ID
+ ".queryArtifactsText";
41 private Button executeBtn
;
42 private Text queryText
;
43 private SashForm sashForm
;
45 private Composite top
, bottom
;
48 public void createPartControl(Composite parent
) {
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
54 sashForm
.setLayout(new FillLayout());
56 top
= new Composite(sashForm
, SWT
.NONE
);
57 top
.setLayout(new GridLayout(1, false));
59 bottom
= new Composite(sashForm
, SWT
.NONE
);
60 bottom
.setLayout(new GridLayout(1, false));
62 sashForm
.setWeights(new int[] { 25, 75 });
65 createResultPart(bottom
);
68 public void createQueryForm(Composite parent
) {
72 GridLayout gl
= new GridLayout(2, false);
76 lbl
= new Label(parent
, SWT
.SINGLE
);
77 lbl
.setText("Enter a JCR:SQL2 Query");
79 executeBtn
= new Button(parent
, SWT
.PUSH
);
80 executeBtn
.setText("Search");
82 queryText
= new Text(parent
, SWT
.MULTI
| SWT
.WRAP
| SWT
.BORDER
);
83 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
84 gd
.grabExcessHorizontalSpace
= true;
86 gd
.horizontalSpan
= 2;
87 queryText
.setLayoutData(gd
);
89 String query
= generateSelectStatement() + generateFromStatement()
90 + generateWhereStatement();
91 queryText
.setText(query
);
93 Listener executeListener
= new Listener() {
94 public void handleEvent(Event event
) {
98 executeBtn
.addListener(SWT
.Selection
, executeListener
);
101 public void refreshQuery() {
102 String queryStr
= queryText
.getText();
103 executeQuery(queryStr
);
108 private String
generateWhereStatement() {
109 StringBuffer sb
= new StringBuffer(" where ");
110 return sb
.toString();
114 public void setFocus() {
115 executeBtn
.setFocus();