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
.SlcTypes
;
21 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.custom
.SashForm
;
24 import org
.eclipse
.swt
.layout
.FillLayout
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Event
;
30 import org
.eclipse
.swt
.widgets
.Label
;
31 import org
.eclipse
.swt
.widgets
.Listener
;
32 import org
.eclipse
.swt
.widgets
.Text
;
34 /** Query SLC Repo to get some artifacts given some predefined parameters */
35 public class QueryBundlesForm
extends AbstractQueryArtifactsView
implements
37 // private static final Log log = LogFactory.getLog(QueryBundlesForm.class);
38 public static final String ID
= DistPlugin
.PLUGIN_ID
+ ".queryBundlesForm";
41 private Button executeBtn
;
42 private Text symbolicName
;
43 private Text importedPackage
;
44 private Text exportedPackage
;
45 private SashForm sashForm
;
47 private Composite top
, bottom
;
50 public void createPartControl(Composite parent
) {
52 sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
53 sashForm
.setSashWidth(4);
54 // Enable the different parts to fill the whole page when the tab is
56 sashForm
.setLayout(new FillLayout());
58 top
= new Composite(sashForm
, SWT
.NONE
);
59 top
.setLayout(new GridLayout(1, false));
61 bottom
= new Composite(sashForm
, SWT
.NONE
);
62 bottom
.setLayout(new GridLayout(1, false));
64 sashForm
.setWeights(new int[] { 25, 75 });
67 createResultPart(bottom
);
70 public void createQueryForm(Composite parent
) {
74 GridLayout gl
= new GridLayout(2, false);
79 lbl
= new Label(parent
, SWT
.SINGLE
);
80 lbl
.setText("Symbolic name");
81 symbolicName
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
82 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
83 gd
.grabExcessHorizontalSpace
= true;
84 symbolicName
.setLayoutData(gd
);
87 lbl
= new Label(parent
, SWT
.SINGLE
);
88 lbl
.setText("Imported package");
89 importedPackage
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
90 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
91 gd
.grabExcessHorizontalSpace
= true;
92 importedPackage
.setLayoutData(gd
);
95 lbl
= new Label(parent
, SWT
.SINGLE
);
96 lbl
.setText("Exported package");
97 exportedPackage
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
98 gd
= new GridData(GridData
.FILL_HORIZONTAL
);
99 gd
.grabExcessHorizontalSpace
= true;
100 exportedPackage
.setLayoutData(gd
);
102 executeBtn
= new Button(parent
, SWT
.PUSH
);
103 executeBtn
.setText("Search");
105 gd
.horizontalSpan
= 2;
106 executeBtn
.setLayoutData(gd
);
108 Listener executeListener
= new Listener() {
109 private static final long serialVersionUID
= 6267263421349073712L;
111 public void handleEvent(Event event
) {
115 executeBtn
.addListener(SWT
.Selection
, executeListener
);
118 public void refreshQuery() {
119 String queryStr
= generateStatement();
120 executeQuery(queryStr
);
125 private String
generateStatement() {
128 boolean hasFirstClause
= false;
129 boolean ipClause
= importedPackage
.getText() != null
130 && !importedPackage
.getText().trim().equals("");
131 boolean epClause
= exportedPackage
.getText() != null
132 && !exportedPackage
.getText().trim().equals("");
134 StringBuffer sb
= new StringBuffer();
136 sb
.append("select " + SBA
+ ".*, " + SAVB
+ ".* ");
137 sb
.append(" from " + SAVB
);
140 sb
.append(" inner join ");
142 sb
.append(" on isdescendantnode(" + SBA
+ ", " + SAVB
+ ") ");
144 sb
.append(" inner join ");
146 sb
.append(" on isdescendantnode(" + SIP
+ ", " + SBA
+ ") ");
150 sb
.append(" inner join ");
152 sb
.append(" on isdescendantnode(" + SEP
+ ", " + SBA
+ ") ");
156 sb
.append(" where ");
157 if (symbolicName
.getText() != null
158 && !symbolicName
.getText().trim().equals("")) {
159 sb
.append(SBA
+ ".[" + SLC_SYMBOLIC_NAME
+ "] like '"
160 + symbolicName
.getText().replace('*', '%') + "'");
161 hasFirstClause
= true;
167 sb
.append(SIP
+ ".[" + SLC_NAME
+ "] like '"
168 + importedPackage
.getText().replace('*', '%') + "'");
169 hasFirstClause
= true;
175 sb
.append(SEP
+ ".[" + SLC_NAME
+ "] like '"
176 + exportedPackage
.getText().replace('*', '%') + "'");
178 return sb
.toString();
179 } catch (Exception e
) {
180 throw new SlcException(
181 "Cannot generate where statement to get artifacts", e
);
186 public void setFocus() {
187 executeBtn
.setFocus();