]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/QueryArtifactsForm.java
Improve dist UI
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / views / QueryArtifactsForm.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.dist.views;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.argeo.ArgeoException;
21 import org.argeo.slc.client.ui.dist.DistPlugin;
22 import org.argeo.slc.jcr.SlcNames;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.custom.SashForm;
25 import org.eclipse.swt.layout.FillLayout;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Event;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.Listener;
33 import org.eclipse.swt.widgets.Text;
34
35 /** Query SLC Repo to get some artifacts given some predefined parameters */
36 public class QueryArtifactsForm extends AbstractQueryArtifactsView implements
37 SlcNames {
38 private static final Log log = LogFactory.getLog(QueryArtifactsForm.class);
39 public static final String ID = DistPlugin.ID + ".queryArtifactsForm";
40
41 // widgets
42 private Button executeBtn;
43 private Text groupId;
44 private Text artifactId;
45 private Text version;
46 private SashForm sashForm;
47
48 private Composite top, bottom;
49
50 @Override
51 public void createPartControl(Composite parent) {
52
53 sashForm = new SashForm(parent, SWT.VERTICAL);
54 sashForm.setSashWidth(4);
55 // Enable the different parts to fill the whole page when the tab is
56 // maximized
57 sashForm.setLayout(new FillLayout());
58
59 top = new Composite(sashForm, SWT.NONE);
60 top.setLayout(new GridLayout(1, false));
61
62 bottom = new Composite(sashForm, SWT.NONE);
63 bottom.setLayout(new GridLayout(1, false));
64
65 sashForm.setWeights(new int[] { 25, 75 });
66
67 createQueryForm(top);
68 createResultPart(bottom);
69 }
70
71 public void createQueryForm(Composite parent) {
72 Label lbl;
73 GridData gd;
74
75 GridLayout gl = new GridLayout(2, false);
76 gl.marginTop = 5;
77 parent.setLayout(gl);
78
79 // lbl = new Label(parent, SWT.SINGLE);
80 // lbl.setText("Query by coordinates");
81 // gd = new GridData();
82 // gd.horizontalSpan = 2;
83 // lbl.setLayoutData(gd);
84
85 // Group ID
86 lbl = new Label(parent, SWT.SINGLE);
87 lbl.setText("Group ID");
88 groupId = new Text(parent, SWT.SINGLE | SWT.BORDER);
89 gd = new GridData(GridData.FILL_HORIZONTAL);
90 gd.grabExcessHorizontalSpace = true;
91 groupId.setLayoutData(gd);
92
93 // Artifact ID
94 lbl = new Label(parent, SWT.SINGLE);
95 lbl.setText("Artifact ID");
96 artifactId = new Text(parent, SWT.SINGLE | SWT.BORDER);
97 gd = new GridData(GridData.FILL_HORIZONTAL);
98 gd.grabExcessHorizontalSpace = true;
99 artifactId.setLayoutData(gd);
100
101 // Version
102 lbl = new Label(parent, SWT.SINGLE);
103 lbl.setText("Version");
104 version = new Text(parent, SWT.SINGLE | SWT.BORDER);
105 gd = new GridData(GridData.FILL_HORIZONTAL);
106 gd.grabExcessHorizontalSpace = true;
107 version.setLayoutData(gd);
108
109 executeBtn = new Button(parent, SWT.PUSH);
110 executeBtn.setText("Search");
111 gd = new GridData();
112 gd.horizontalSpan = 2;
113 executeBtn.setLayoutData(gd);
114
115 Listener executeListener = new Listener() {
116 public void handleEvent(Event event) {
117 refreshQuery();
118 }
119 };
120 executeBtn.addListener(SWT.Selection, executeListener);
121 }
122
123 public void refreshQuery() {
124 String queryStr = generateSelectStatement() + generateFromStatement()
125 + generateWhereStatement();
126 executeQuery(queryStr);
127 bottom.layout();
128 sashForm.layout();
129 }
130
131 private String generateWhereStatement() {
132 try {
133 boolean hasFirstClause = false;
134 StringBuffer sb = new StringBuffer(" where ");
135
136 if (groupId.getText() != null
137 && !groupId.getText().trim().equals("")) {
138 sb.append("[" + SLC_GROUP_ID + "] like '"
139 + groupId.getText().replace('*', '%') + "'");
140 hasFirstClause = true;
141 }
142
143 if (artifactId.getText() != null
144 && !artifactId.getText().trim().equals("")) {
145 if (hasFirstClause)
146 sb.append(" AND ");
147 sb.append("[" + SLC_ARTIFACT_ID + "] like '"
148 + artifactId.getText().replace('*', '%') + "'");
149 hasFirstClause = true;
150 }
151
152 if (version.getText() != null
153 && !version.getText().trim().equals("")) {
154 if (hasFirstClause)
155 sb.append(" AND ");
156 sb.append("[" + SLC_ARTIFACT_VERSION + "] like '"
157 + version.getText().replace('*', '%') + "'");
158 }
159
160 return sb.toString();
161 } catch (Exception e) {
162 throw new ArgeoException(
163 "Cannot generate where statement to get artifacts", e);
164 }
165 }
166
167 @Override
168 public void setFocus() {
169 executeBtn.setFocus();
170 }
171 }