]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.akb.ui/src/main/java/org/argeo/slc/akb/ui/views/AkbDefaultView.java
Prepare SLC v1.1.15 release
[gpl/argeo-slc.git] / plugins / org.argeo.slc.akb.ui / src / main / java / org / argeo / slc / akb / ui / views / AkbDefaultView.java
1 package org.argeo.slc.akb.ui.views;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.jcr.Node;
7 import javax.jcr.Repository;
8 import javax.jcr.RepositoryException;
9 import javax.jcr.Session;
10
11 import org.argeo.eclipse.ui.utils.CommandUtils;
12 import org.argeo.jcr.JcrUtils;
13 import org.argeo.slc.akb.AkbException;
14 import org.argeo.slc.akb.ui.AkbUiPlugin;
15 import org.argeo.slc.akb.ui.commands.OpenAkbNodeEditor;
16 import org.argeo.slc.akb.ui.composites.AkbItemsTableComposite;
17 import org.argeo.slc.akb.utils.AkbJcrUtils;
18 import org.eclipse.jface.viewers.DoubleClickEvent;
19 import org.eclipse.jface.viewers.IDoubleClickListener;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.ui.part.ViewPart;
26
27 /** Basic view that display a list of items with a quick search field. */
28 public class AkbDefaultView extends ViewPart {
29 // private final static Log log = LogFactory.getLog(QuickSearchView.class);
30
31 public static final String ID = AkbUiPlugin.PLUGIN_ID + ".akbDefaultView";
32
33 /* DEPENDENCY INJECTION */
34 private Session session;
35
36 // This page widgets
37 private AkbItemsTableComposite userTableCmp;
38
39 @Override
40 public void createPartControl(Composite parent) {
41 GridLayout gl = new GridLayout();
42 gl.horizontalSpacing = gl.verticalSpacing = gl.marginWidth = 0;
43 parent.setLayout(gl);
44
45 // Create the composite that displays the list and a filter
46 AkbItemsTableComposite userTableCmp = new AkbItemsTableComposite(
47 parent, SWT.NO_FOCUS, session);
48 userTableCmp.populate(true, false);
49 userTableCmp
50 .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
51
52 // Configure
53 userTableCmp.getTableViewer().addDoubleClickListener(
54 new ViewDoubleClickListener());
55 getViewSite().setSelectionProvider(userTableCmp.getTableViewer());
56
57 // // Filter
58 // Composite cmp = new Composite(parent, SWT.NO_FOCUS);
59 // cmp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
60 // createFilterPart(cmp);
61 //
62 // // Table
63 // cmp = new Composite(parent, SWT.NO_FOCUS);
64 // cmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
65 // itemViewer = createListPart(cmp);
66 //
67 // // refreshFilteredList();
68 }
69
70 class ViewDoubleClickListener implements IDoubleClickListener {
71 public void doubleClick(DoubleClickEvent evt) {
72 Object obj = ((IStructuredSelection) evt.getSelection())
73 .getFirstElement();
74 try {
75 if (obj instanceof Node) {
76 Node node = (Node) obj;
77 Node currEnv = AkbJcrUtils.getCurrentTemplate(node);
78
79 // Add Connector Alias
80 Map<String, String> params = new HashMap<String, String>();
81 params.put(OpenAkbNodeEditor.PARAM_NODE_JCR_ID,
82 node.getIdentifier());
83 params.put(OpenAkbNodeEditor.PARAM_CURR_ENV_JCR_ID,
84 currEnv.getIdentifier());
85
86 CommandUtils.callCommand(OpenAkbNodeEditor.ID, params);
87 }
88 } catch (RepositoryException e) {
89 throw new AkbException("Cannot open " + obj, e);
90 }
91 }
92 }
93
94 // private void createFilterPart(Composite parent) {
95 // parent.setLayout(new GridLayout());
96 // // Text Area for the filter
97 // filterTxt = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH
98 // | SWT.ICON_CANCEL);
99 // filterTxt.setMessage(FILTER_HELP_MSG);
100 // filterTxt.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
101 // filterTxt.addModifyListener(new ModifyListener() {
102 //
103 // public void modifyText(ModifyEvent event) {
104 // refreshFilteredList();
105 // }
106 // });
107 // }
108 //
109 // protected TableViewer createListPart(Composite parent) {
110 // TableViewer v = new TableViewer(parent);
111 //
112 // TableColumn singleColumn = new TableColumn(v.getTable(), SWT.V_SCROLL);
113 // TableColumnLayout tableColumnLayout = new TableColumnLayout();
114 // tableColumnLayout.setColumnData(singleColumn, new ColumnWeightData(85));
115 // parent.setLayout(tableColumnLayout);
116 //
117 // // Corresponding table & style
118 // Table table = v.getTable();
119 // table.setLinesVisible(true);
120 // table.setHeaderVisible(false);
121 //
122 // v.setContentProvider(new BasicNodeListContentProvider());
123 // v.addDoubleClickListener(peopleUiService
124 // .getNewNodeListDoubleClickListener(peopleService, null));
125 // return v;
126 // }
127
128 @Override
129 public void dispose() {
130 userTableCmp.dispose();
131 JcrUtils.logoutQuietly(session);
132 super.dispose();
133 }
134
135 @Override
136 public void setFocus() {
137 }
138
139 // protected void refreshFilteredList() {
140 // try {
141 // List<Node> persons = JcrUtils.nodeIteratorToList(doSearch(session,
142 // filterTxt.getText(), PeopleTypes.PEOPLE_PERSON,
143 // PeopleNames.PEOPLE_LAST_NAME,
144 // PeopleNames.PEOPLE_PRIMARY_EMAIL));
145 // personViewer.setInput(persons);
146 // } catch (RepositoryException e) {
147 // throw new PeopleException("Unable to list persons", e);
148 // }
149 // }
150 //
151 // /** Build repository request */
152 // private NodeIterator doSearch(Session session, String filter,
153 // String typeName, String orderProperty, String orderProperty2)
154 // throws RepositoryException {
155 // QueryManager queryManager = session.getWorkspace().getQueryManager();
156 // QueryObjectModelFactory factory = queryManager.getQOMFactory();
157 //
158 // Selector source = factory.selector(typeName, typeName);
159 //
160 // // no Default Constraint
161 // Constraint defaultC = null;
162 //
163 // // Parse the String
164 // String[] strs = filter.trim().split(" ");
165 // if (strs.length == 0) {
166 // // StaticOperand so = factory.literal(session.getValueFactory()
167 // // .createValue("*"));
168 // // defaultC = factory.fullTextSearch("selector", null, so);
169 // } else {
170 // for (String token : strs) {
171 // StaticOperand so = factory.literal(session.getValueFactory()
172 // .createValue("*" + token + "*"));
173 // Constraint currC = factory.fullTextSearch(
174 // source.getSelectorName(), null, so);
175 // if (defaultC == null)
176 // defaultC = currC;
177 // else
178 // defaultC = factory.and(defaultC, currC);
179 // }
180 // }
181 //
182 // Ordering order = null, order2 = null;
183 //
184 // if (orderProperty != null && !"".equals(orderProperty.trim()))
185 // order = factory.ascending(factory.lowerCase(factory.propertyValue(
186 // source.getSelectorName(), orderProperty)));
187 // if (orderProperty2 != null && !"".equals(orderProperty2.trim()))
188 // order2 = factory.ascending(factory.propertyValue(
189 // source.getSelectorName(), orderProperty2));
190 //
191 // QueryObjectModel query;
192 // if (order == null) {
193 // query = factory.createQuery(source, defaultC, null, null);
194 // } else {
195 // if (order2 == null)
196 // query = factory.createQuery(source, defaultC,
197 // new Ordering[] { order }, null);
198 // else
199 // query = factory.createQuery(source, defaultC, new Ordering[] {
200 // order, order2 }, null);
201 // }
202 // query.setLimit(ROW_LIMIT.longValue());
203 // QueryResult result = query.execute();
204 // return result.getNodes();
205 // }
206
207 /* DEPENDENCY INJECTION */
208 public void setRepository(Repository repository) {
209 try {
210 session = repository.login();
211 } catch (RepositoryException e) {
212 throw new AkbException("Unable to initialize "
213 + "session for view " + ID, e);
214 }
215 }
216 }