1 package org
.argeo
.slc
.client
.ui
.dist
.views
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.ArgeoException
;
6 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
7 import org
.argeo
.slc
.jcr
.SlcNames
;
8 import org
.eclipse
.swt
.SWT
;
9 import org
.eclipse
.swt
.custom
.SashForm
;
10 import org
.eclipse
.swt
.layout
.GridData
;
11 import org
.eclipse
.swt
.layout
.GridLayout
;
12 import org
.eclipse
.swt
.widgets
.Button
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Event
;
15 import org
.eclipse
.swt
.widgets
.Label
;
16 import org
.eclipse
.swt
.widgets
.Listener
;
17 import org
.eclipse
.swt
.widgets
.Text
;
19 /** Query SLC Repo to get some artifacts given some predefined parameters */
20 public class QueryArtifactsForm
extends AbstractQueryArtifactsView
implements
22 private static final Log log
= LogFactory
.getLog(QueryArtifactsForm
.class);
23 public static final String ID
= DistPlugin
.ID
+ ".queryArtifactsForm";
26 private Button executeBtn
;
28 private Text artifactId
;
30 private SashForm sashForm
;
32 private Composite top
, bottom
;
35 public void createPartControl(Composite parent
) {
37 sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
38 sashForm
.setSashWidth(4);
39 sashForm
.setLayout(new GridLayout(1, false));
41 top
= new Composite(sashForm
, SWT
.NONE
);
42 top
.setLayout(new GridLayout(1, false));
44 bottom
= new Composite(sashForm
, SWT
.NONE
);
45 bottom
.setLayout(new GridLayout(1, false));
47 sashForm
.setWeights(new int[] { 25, 75 });
50 createResultPart(bottom
);
53 public void createQueryForm(Composite parent
) {
57 GridLayout gl
= new GridLayout(2, false);
61 lbl
= new Label(parent
, SWT
.SINGLE
);
62 lbl
.setText("Query by coordinates");
64 gd
.horizontalSpan
= 2;
65 lbl
.setLayoutData(gd
);
68 lbl
= new Label(parent
, SWT
.SINGLE
);
69 lbl
.setText("Group ID:");
70 groupId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
73 lbl
= new Label(parent
, SWT
.SINGLE
);
74 lbl
.setText("Artifact ID:");
75 artifactId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
78 lbl
= new Label(parent
, SWT
.SINGLE
);
79 lbl
.setText("Version:");
80 version
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
82 executeBtn
= new Button(parent
, SWT
.PUSH
);
83 executeBtn
.setText("Search");
85 gd
.horizontalSpan
= 2;
86 executeBtn
.setLayoutData(gd
);
88 Listener executeListener
= new Listener() {
89 public void handleEvent(Event event
) {
93 executeBtn
.addListener(SWT
.Selection
, executeListener
);
96 public void refreshQuery() {
97 String queryStr
= generateSelectStatement() + generateFromStatement()
98 + generateWhereStatement();
99 executeQuery(queryStr
);
104 private String
generateWhereStatement() {
106 boolean hasFirstClause
= false;
107 StringBuffer sb
= new StringBuffer(" where ");
109 if (groupId
.getText() != null
110 && !groupId
.getText().trim().equals("")) {
111 sb
.append("[" + SLC_GROUP_ID
+ "] like '"
112 + groupId
.getText().replace('*', '%') + "'");
113 hasFirstClause
= true;
116 if (artifactId
.getText() != null
117 && !artifactId
.getText().trim().equals("")) {
120 sb
.append("[" + SLC_ARTIFACT_ID
+ "] like '"
121 + artifactId
.getText().replace('*', '%') + "'");
122 hasFirstClause
= true;
125 if (version
.getText() != null
126 && !version
.getText().trim().equals("")) {
129 sb
.append("[" + SLC_ARTIFACT_VERSION
+ "] like '"
130 + version
.getText().replace('*', '%') + "'");
133 return sb
.toString();
134 } catch (Exception e
) {
135 throw new ArgeoException(
136 "Cannot generate where statement to get artifacts", e
);
141 public void setFocus() {
142 executeBtn
.setFocus();