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 QueryBundlesForm
extends AbstractQueryArtifactsView
implements
22 private static final Log log
= LogFactory
.getLog(QueryBundlesForm
.class);
23 public static final String ID
= DistPlugin
.ID
+ ".queryArtifactsForm";
26 private Button executeBtn
;
27 private Text symbolicName
;
28 private Text importedPackage
;
29 private Text exportedPackage
;
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);
62 lbl
= new Label(parent
, SWT
.SINGLE
);
63 lbl
.setText("Bundle name: ");
64 symbolicName
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
67 lbl
= new Label(parent
, SWT
.SINGLE
);
68 lbl
.setText("Imported package: ");
69 importedPackage
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
72 lbl
= new Label(parent
, SWT
.SINGLE
);
73 lbl
.setText("Exported package: ");
74 exportedPackage
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
76 executeBtn
= new Button(parent
, SWT
.PUSH
);
77 executeBtn
.setText("Search");
79 gd
.horizontalSpan
= 2;
80 executeBtn
.setLayoutData(gd
);
82 Listener executeListener
= new Listener() {
83 public void handleEvent(Event event
) {
87 executeBtn
.addListener(SWT
.Selection
, executeListener
);
90 public void refreshQuery() {
91 String queryStr
= generateStatement();
92 executeQuery(queryStr
);
97 private String
generateStatement() {
100 boolean hasFirstClause
= false;
101 boolean ipClause
= importedPackage
.getText() != null
102 && !importedPackage
.getText().trim().equals("");
103 boolean epClause
= exportedPackage
.getText() != null
104 && !exportedPackage
.getText().trim().equals("");
106 StringBuffer sb
= new StringBuffer();
108 sb
.append("select p.* ");
112 sb
.append(" from [");
113 sb
.append(SLC_BUNDLE_ARTIFACT
);
114 sb
.append("] as sa ");
117 sb
.append(" inner join [");
118 sb
.append(SLC_BUNDLE_ARTIFACT
);
119 sb
.append("] as sa on isdescendantnode(sa, sba)");
122 sb
.append(" where ");
124 if (symbolicName
.getText() != null
125 && !symbolicName
.getText().trim().equals("")) {
126 sb
.append("sba.[" + SLC_SYMBOLIC_NAME
+ "] like '"
127 + symbolicName
.getText().replace('*', '%') + "'");
128 hasFirstClause
= true;
134 sb
.append("[" + SLC_ARTIFACT_ID
+ "] like '"
135 + importedPackage
.getText().replace('*', '%') + "'");
136 hasFirstClause
= true;
142 sb
.append("[" + SLC_ARTIFACT_ID
+ "] like '"
143 + exportedPackage
.getText().replace('*', '%') + "'");
144 hasFirstClause
= true;
147 return sb
.toString();
148 } catch (Exception e
) {
149 throw new ArgeoException(
150 "Cannot generate where statement to get artifacts", e
);
155 public void setFocus() {
156 executeBtn
.setFocus();