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
.FillLayout
;
11 import org
.eclipse
.swt
.layout
.GridData
;
12 import org
.eclipse
.swt
.layout
.GridLayout
;
13 import org
.eclipse
.swt
.widgets
.Button
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Event
;
16 import org
.eclipse
.swt
.widgets
.Label
;
17 import org
.eclipse
.swt
.widgets
.Listener
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 /** Query SLC Repo to get some artifacts given some predefined parameters */
21 public class QueryArtifactsForm
extends AbstractQueryArtifactsView
implements
23 private static final Log log
= LogFactory
.getLog(QueryArtifactsForm
.class);
24 public static final String ID
= DistPlugin
.ID
+ ".queryArtifactsForm";
27 private Button executeBtn
;
29 private Text artifactId
;
31 private SashForm sashForm
;
33 private Composite top
, bottom
;
36 public void createPartControl(Composite parent
) {
38 sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
39 sashForm
.setSashWidth(4);
40 // Enable the different parts to fill the whole page when the tab is
42 sashForm
.setLayout(new FillLayout());
44 top
= new Composite(sashForm
, SWT
.NONE
);
45 top
.setLayout(new GridLayout(1, false));
47 bottom
= new Composite(sashForm
, SWT
.NONE
);
48 bottom
.setLayout(new GridLayout(1, false));
50 sashForm
.setWeights(new int[] { 25, 75 });
53 createResultPart(bottom
);
56 public void createQueryForm(Composite parent
) {
60 GridLayout gl
= new GridLayout(2, false);
64 // lbl = new Label(parent, SWT.SINGLE);
65 // lbl.setText("Query by coordinates");
66 // gd = new GridData();
67 // gd.horizontalSpan = 2;
68 // lbl.setLayoutData(gd);
71 lbl
= new Label(parent
, SWT
.SINGLE
);
72 lbl
.setText("Group ID");
73 groupId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
74 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
75 gd
.grabExcessHorizontalSpace
= true;
76 groupId
.setLayoutData(gd
);
79 lbl
= new Label(parent
, SWT
.SINGLE
);
80 lbl
.setText("Artifact ID");
81 artifactId
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
82 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
83 gd
.grabExcessHorizontalSpace
= true;
84 artifactId
.setLayoutData(gd
);
87 lbl
= new Label(parent
, SWT
.SINGLE
);
88 lbl
.setText("Version");
89 version
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
90 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
91 gd
.grabExcessHorizontalSpace
= true;
92 version
.setLayoutData(gd
);
94 executeBtn
= new Button(parent
, SWT
.PUSH
);
95 executeBtn
.setText("Search");
97 gd
.horizontalSpan
= 2;
98 executeBtn
.setLayoutData(gd
);
100 Listener executeListener
= new Listener() {
101 public void handleEvent(Event event
) {
105 executeBtn
.addListener(SWT
.Selection
, executeListener
);
108 public void refreshQuery() {
109 String queryStr
= generateSelectStatement() + generateFromStatement()
110 + generateWhereStatement();
111 executeQuery(queryStr
);
116 private String
generateWhereStatement() {
118 boolean hasFirstClause
= false;
119 StringBuffer sb
= new StringBuffer(" where ");
121 if (groupId
.getText() != null
122 && !groupId
.getText().trim().equals("")) {
123 sb
.append("[" + SLC_GROUP_ID
+ "] like '"
124 + groupId
.getText().replace('*', '%') + "'");
125 hasFirstClause
= true;
128 if (artifactId
.getText() != null
129 && !artifactId
.getText().trim().equals("")) {
132 sb
.append("[" + SLC_ARTIFACT_ID
+ "] like '"
133 + artifactId
.getText().replace('*', '%') + "'");
134 hasFirstClause
= true;
137 if (version
.getText() != null
138 && !version
.getText().trim().equals("")) {
141 sb
.append("[" + SLC_ARTIFACT_VERSION
+ "] like '"
142 + version
.getText().replace('*', '%') + "'");
145 return sb
.toString();
146 } catch (Exception e
) {
147 throw new ArgeoException(
148 "Cannot generate where statement to get artifacts", e
);
153 public void setFocus() {
154 executeBtn
.setFocus();