]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/QueryArtifactsForm.java
First version of dist UI
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / views / QueryArtifactsForm.java
1 package org.argeo.slc.client.ui.dist.views;
2
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;
19
20 /** Query SLC Repo to get some artifacts given some predefined parameters */
21 public class QueryArtifactsForm extends AbstractQueryArtifactsView implements
22 SlcNames {
23 private static final Log log = LogFactory.getLog(QueryArtifactsForm.class);
24 public static final String ID = DistPlugin.ID + ".queryArtifactsForm";
25
26 // widgets
27 private Button executeBtn;
28 private Text groupId;
29 private Text artifactId;
30 private Text version;
31 private SashForm sashForm;
32
33 private Composite top, bottom;
34
35 @Override
36 public void createPartControl(Composite parent) {
37
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
41 // maximized
42 sashForm.setLayout(new FillLayout());
43
44 top = new Composite(sashForm, SWT.NONE);
45 top.setLayout(new GridLayout(1, false));
46
47 bottom = new Composite(sashForm, SWT.NONE);
48 bottom.setLayout(new GridLayout(1, false));
49
50 sashForm.setWeights(new int[] { 25, 75 });
51
52 createQueryForm(top);
53 createResultPart(bottom);
54 }
55
56 public void createQueryForm(Composite parent) {
57 Label lbl;
58 GridData gd;
59
60 GridLayout gl = new GridLayout(2, false);
61 gl.marginTop = 5;
62 parent.setLayout(gl);
63
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);
69
70 // Group ID
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);
77
78 // Artifact ID
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);
85
86 // Version
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);
93
94 executeBtn = new Button(parent, SWT.PUSH);
95 executeBtn.setText("Search");
96 gd = new GridData();
97 gd.horizontalSpan = 2;
98 executeBtn.setLayoutData(gd);
99
100 Listener executeListener = new Listener() {
101 public void handleEvent(Event event) {
102 refreshQuery();
103 }
104 };
105 executeBtn.addListener(SWT.Selection, executeListener);
106 }
107
108 public void refreshQuery() {
109 String queryStr = generateSelectStatement() + generateFromStatement()
110 + generateWhereStatement();
111 executeQuery(queryStr);
112 bottom.layout();
113 sashForm.layout();
114 }
115
116 private String generateWhereStatement() {
117 try {
118 boolean hasFirstClause = false;
119 StringBuffer sb = new StringBuffer(" where ");
120
121 if (groupId.getText() != null
122 && !groupId.getText().trim().equals("")) {
123 sb.append("[" + SLC_GROUP_ID + "] like '"
124 + groupId.getText().replace('*', '%') + "'");
125 hasFirstClause = true;
126 }
127
128 if (artifactId.getText() != null
129 && !artifactId.getText().trim().equals("")) {
130 if (hasFirstClause)
131 sb.append(" AND ");
132 sb.append("[" + SLC_ARTIFACT_ID + "] like '"
133 + artifactId.getText().replace('*', '%') + "'");
134 hasFirstClause = true;
135 }
136
137 if (version.getText() != null
138 && !version.getText().trim().equals("")) {
139 if (hasFirstClause)
140 sb.append(" AND ");
141 sb.append("[" + SLC_ARTIFACT_VERSION + "] like '"
142 + version.getText().replace('*', '%') + "'");
143 }
144
145 return sb.toString();
146 } catch (Exception e) {
147 throw new ArgeoException(
148 "Cannot generate where statement to get artifacts", e);
149 }
150 }
151
152 @Override
153 public void setFocus() {
154 executeBtn.setFocus();
155 }
156 }