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
.argeo
.slc
.SlcException
;
19 import org
.argeo
.slc
.SlcNames
;
20 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.custom
.SashForm
;
23 import org
.eclipse
.swt
.layout
.FillLayout
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Button
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Event
;
29 import org
.eclipse
.swt
.widgets
.Label
;
30 import org
.eclipse
.swt
.widgets
.Listener
;
31 import org
.eclipse
.swt
.widgets
.Text
;
33 /** Query SLC Repo to get some artifacts given some predefined parameters */
34 public class QueryArtifactsForm
extends AbstractQueryArtifactsView
implements
36 // private static final Log log = LogFactory.getLog(QueryArtifactsForm.class);
37 public static final String ID
= DistPlugin
.PLUGIN_ID
+ ".queryArtifactsForm";
40 private Button executeBtn
;
42 private Text artifactId
;
44 private SashForm sashForm
;
46 private Composite top
, bottom
;
49 public void createPartControl(Composite parent
) {
51 sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
52 sashForm
.setSashWidth(4);
53 // Enable the different parts to fill the whole page when the tab is
55 sashForm
.setLayout(new FillLayout());
57 top
= new Composite(sashForm
, SWT
.NONE
);
58 top
.setLayout(new GridLayout(1, false));
60 bottom
= new Composite(sashForm
, SWT
.NONE
);
61 bottom
.setLayout(new GridLayout(1, false));
63 sashForm
.setWeights(new int[] { 25, 75 });
66 createResultPart(bottom
);
69 public void createQueryForm(Composite parent
) {
73 GridLayout gl
= new GridLayout(2, false);
77 // lbl = new Label(parent, SWT.SINGLE);
78 // lbl.setText("Query by coordinates");
79 // gd = new GridData();
80 // gd.horizontalSpan = 2;
81 // lbl.setLayoutData(gd);
84 lbl
= new Label(parent
, SWT
.SINGLE
);
85 lbl
.setText("Group ID");
86 groupId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
87 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
88 gd
.grabExcessHorizontalSpace
= true;
89 groupId
.setLayoutData(gd
);
92 lbl
= new Label(parent
, SWT
.SINGLE
);
93 lbl
.setText("Artifact ID");
94 artifactId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
95 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
96 gd
.grabExcessHorizontalSpace
= true;
97 artifactId
.setLayoutData(gd
);
100 lbl
= new Label(parent
, SWT
.SINGLE
);
101 lbl
.setText("Version");
102 version
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
103 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
104 gd
.grabExcessHorizontalSpace
= true;
105 version
.setLayoutData(gd
);
107 executeBtn
= new Button(parent
, SWT
.PUSH
);
108 executeBtn
.setText("Search");
110 gd
.horizontalSpan
= 2;
111 executeBtn
.setLayoutData(gd
);
113 Listener executeListener
= new Listener() {
114 private static final long serialVersionUID
= 7161585477628774129L;
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 SlcException(
163 "Cannot generate where statement to get artifacts", e
);
168 public void setFocus() {
169 executeBtn
.setFocus();