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
.ArgeoException
;
21 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
22 import org
.argeo
.slc
.jcr
.SlcNames
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.custom
.SashForm
;
25 import org
.eclipse
.swt
.layout
.FillLayout
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Button
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Event
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Listener
;
33 import org
.eclipse
.swt
.widgets
.Text
;
35 /** Query SLC Repo to get some artifacts given some predefined parameters */
36 public class QueryArtifactsForm
extends AbstractQueryArtifactsView
implements
38 private static final Log log
= LogFactory
.getLog(QueryArtifactsForm
.class);
39 public static final String ID
= DistPlugin
.ID
+ ".queryArtifactsForm";
42 private Button executeBtn
;
44 private Text artifactId
;
46 private SashForm sashForm
;
48 private Composite top
, bottom
;
51 public void createPartControl(Composite parent
) {
53 sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
54 sashForm
.setSashWidth(4);
55 // Enable the different parts to fill the whole page when the tab is
57 sashForm
.setLayout(new FillLayout());
59 top
= new Composite(sashForm
, SWT
.NONE
);
60 top
.setLayout(new GridLayout(1, false));
62 bottom
= new Composite(sashForm
, SWT
.NONE
);
63 bottom
.setLayout(new GridLayout(1, false));
65 sashForm
.setWeights(new int[] { 25, 75 });
68 createResultPart(bottom
);
71 public void createQueryForm(Composite parent
) {
75 GridLayout gl
= new GridLayout(2, false);
79 // lbl = new Label(parent, SWT.SINGLE);
80 // lbl.setText("Query by coordinates");
81 // gd = new GridData();
82 // gd.horizontalSpan = 2;
83 // lbl.setLayoutData(gd);
86 lbl
= new Label(parent
, SWT
.SINGLE
);
87 lbl
.setText("Group ID");
88 groupId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
89 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
90 gd
.grabExcessHorizontalSpace
= true;
91 groupId
.setLayoutData(gd
);
94 lbl
= new Label(parent
, SWT
.SINGLE
);
95 lbl
.setText("Artifact ID");
96 artifactId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
97 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
98 gd
.grabExcessHorizontalSpace
= true;
99 artifactId
.setLayoutData(gd
);
102 lbl
= new Label(parent
, SWT
.SINGLE
);
103 lbl
.setText("Version");
104 version
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
105 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
106 gd
.grabExcessHorizontalSpace
= true;
107 version
.setLayoutData(gd
);
109 executeBtn
= new Button(parent
, SWT
.PUSH
);
110 executeBtn
.setText("Search");
112 gd
.horizontalSpan
= 2;
113 executeBtn
.setLayoutData(gd
);
115 Listener executeListener
= new Listener() {
116 public void handleEvent(Event event
) {
120 executeBtn
.addListener(SWT
.Selection
, executeListener
);
123 public void refreshQuery() {
124 String queryStr
= generateSelectStatement() + generateFromStatement()
125 + generateWhereStatement();
126 executeQuery(queryStr
);
131 private String
generateWhereStatement() {
133 boolean hasFirstClause
= false;
134 StringBuffer sb
= new StringBuffer(" where ");
136 if (groupId
.getText() != null
137 && !groupId
.getText().trim().equals("")) {
138 sb
.append("[" + SLC_GROUP_ID
+ "] like '"
139 + groupId
.getText().replace('*', '%') + "'");
140 hasFirstClause
= true;
143 if (artifactId
.getText() != null
144 && !artifactId
.getText().trim().equals("")) {
147 sb
.append("[" + SLC_ARTIFACT_ID
+ "] like '"
148 + artifactId
.getText().replace('*', '%') + "'");
149 hasFirstClause
= true;
152 if (version
.getText() != null
153 && !version
.getText().trim().equals("")) {
156 sb
.append("[" + SLC_ARTIFACT_VERSION
+ "] like '"
157 + version
.getText().replace('*', '%') + "'");
160 return sb
.toString();
161 } catch (Exception e
) {
162 throw new ArgeoException(
163 "Cannot generate where statement to get artifacts", e
);
168 public void setFocus() {
169 executeBtn
.setFocus();