1 package org
.argeo
.slc
.akb
.ui
.views
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.Repository
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.Session
;
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
;
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);
31 public static final String ID
= AkbUiPlugin
.PLUGIN_ID
+ ".akbDefaultView";
33 /* DEPENDENCY INJECTION */
34 private Session session
;
37 private AkbItemsTableComposite userTableCmp
;
40 public void createPartControl(Composite parent
) {
41 GridLayout gl
= new GridLayout();
42 gl
.horizontalSpacing
= gl
.verticalSpacing
= gl
.marginWidth
= 0;
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);
50 .setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
53 userTableCmp
.getTableViewer().addDoubleClickListener(
54 new ViewDoubleClickListener());
55 getViewSite().setSelectionProvider(userTableCmp
.getTableViewer());
58 // Composite cmp = new Composite(parent, SWT.NO_FOCUS);
59 // cmp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
60 // createFilterPart(cmp);
63 // cmp = new Composite(parent, SWT.NO_FOCUS);
64 // cmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
65 // itemViewer = createListPart(cmp);
67 // // refreshFilteredList();
70 class ViewDoubleClickListener
implements IDoubleClickListener
{
71 public void doubleClick(DoubleClickEvent evt
) {
72 Object obj
= ((IStructuredSelection
) evt
.getSelection())
75 if (obj
instanceof Node
) {
76 Node node
= (Node
) obj
;
77 Node currEnv
= AkbJcrUtils
.getCurrentTemplate(node
);
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());
86 CommandUtils
.callCommand(OpenAkbNodeEditor
.ID
, params
);
88 } catch (RepositoryException e
) {
89 throw new AkbException("Cannot open " + obj
, e
);
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() {
103 // public void modifyText(ModifyEvent event) {
104 // refreshFilteredList();
109 // protected TableViewer createListPart(Composite parent) {
110 // TableViewer v = new TableViewer(parent);
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);
117 // // Corresponding table & style
118 // Table table = v.getTable();
119 // table.setLinesVisible(true);
120 // table.setHeaderVisible(false);
122 // v.setContentProvider(new BasicNodeListContentProvider());
123 // v.addDoubleClickListener(peopleUiService
124 // .getNewNodeListDoubleClickListener(peopleService, null));
129 public void dispose() {
130 userTableCmp
.dispose();
131 JcrUtils
.logoutQuietly(session
);
136 public void setFocus() {
139 // protected void refreshFilteredList() {
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);
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();
158 // Selector source = factory.selector(typeName, typeName);
160 // // no Default Constraint
161 // Constraint defaultC = null;
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);
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)
178 // defaultC = factory.and(defaultC, currC);
182 // Ordering order = null, order2 = null;
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));
191 // QueryObjectModel query;
192 // if (order == null) {
193 // query = factory.createQuery(source, defaultC, null, null);
195 // if (order2 == null)
196 // query = factory.createQuery(source, defaultC,
197 // new Ordering[] { order }, null);
199 // query = factory.createQuery(source, defaultC, new Ordering[] {
200 // order, order2 }, null);
202 // query.setLimit(ROW_LIMIT.longValue());
203 // QueryResult result = query.execute();
204 // return result.getNodes();
207 /* DEPENDENCY INJECTION */
208 public void setRepository(Repository repository
) {
210 session
= repository
.login();
211 } catch (RepositoryException e
) {
212 throw new AkbException("Unable to initialize "
213 + "session for view " + ID
, e
);