1 //package org.argeo.eclipse.ui.workbench.osgi;
2 //public class BundlesView {}
5 * Copyright (C) 2007-2012 Argeo GmbH
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org
.argeo
.cms
.ui
.workbench
.osgi
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collection
;
23 import java
.util
.List
;
25 import javax
.naming
.ldap
.LdapName
;
27 import org
.argeo
.cms
.CmsException
;
28 import org
.argeo
.cms
.auth
.CmsSession
;
29 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
30 import org
.argeo
.eclipse
.ui
.ColumnViewerComparator
;
31 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
32 import org
.argeo
.util
.LangUtils
;
33 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
34 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
35 import org
.eclipse
.jface
.viewers
.TableViewer
;
36 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
37 import org
.eclipse
.jface
.viewers
.Viewer
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.ui
.part
.ViewPart
;
41 import org
.osgi
.framework
.BundleContext
;
42 import org
.osgi
.framework
.InvalidSyntaxException
;
43 import org
.osgi
.framework
.ServiceReference
;
46 * Overview of the active CMS sessions.
48 public class CmsSessionsView
extends ViewPart
{
49 private TableViewer viewer
;
52 public void createPartControl(Composite parent
) {
53 viewer
= new TableViewer(parent
);
54 viewer
.setContentProvider(new CmsSessionContentProvider());
55 viewer
.getTable().setHeaderVisible(true);
57 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
59 int longColWidth
= 150;
60 int smallColWidth
= 100;
63 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
64 column
.getColumn().setWidth(longColWidth
);
65 column
.getColumn().setText("User");
66 column
.setLabelProvider(new ColumnLabelProvider() {
67 private static final long serialVersionUID
= -5234573509093747505L;
69 public String
getText(Object element
) {
70 return ((CmsSession
) element
).getAuthorization().toString();
73 public String
getToolTipText(Object element
) {
74 return ((CmsSession
) element
).getUserDn().toString();
77 new ColumnViewerComparator(column
);
80 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
81 column
.getColumn().setWidth(smallColWidth
);
82 column
.getColumn().setText("Since");
83 column
.setLabelProvider(new ColumnLabelProvider() {
84 private static final long serialVersionUID
= -5234573509093747505L;
86 public String
getText(Object element
) {
87 return LangUtils
.since(((CmsSession
) element
).getCreationTime());
90 public String
getToolTipText(Object element
) {
91 return ((CmsSession
) element
).getCreationTime().toString();
94 new ColumnViewerComparator(column
);
97 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
98 column
.getColumn().setWidth(smallColWidth
);
99 column
.getColumn().setText("Username");
100 column
.setLabelProvider(new ColumnLabelProvider() {
101 private static final long serialVersionUID
= -5234573509093747505L;
103 public String
getText(Object element
) {
104 LdapName userDn
= ((CmsSession
) element
).getUserDn();
105 return userDn
.getRdn(userDn
.size() - 1).getValue().toString();
108 public String
getToolTipText(Object element
) {
109 return ((CmsSession
) element
).getUserDn().toString();
112 new ColumnViewerComparator(column
);
115 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
116 column
.getColumn().setWidth(smallColWidth
);
117 column
.getColumn().setText("UUID");
118 column
.setLabelProvider(new ColumnLabelProvider() {
119 private static final long serialVersionUID
= -5234573509093747505L;
121 public String
getText(Object element
) {
122 return ((CmsSession
) element
).getUuid().toString();
125 public String
getToolTipText(Object element
) {
126 return getText(element
);
129 new ColumnViewerComparator(column
);
132 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
133 column
.getColumn().setWidth(smallColWidth
);
134 column
.getColumn().setText("Local ID");
135 column
.setLabelProvider(new ColumnLabelProvider() {
136 private static final long serialVersionUID
= -5234573509093747505L;
138 public String
getText(Object element
) {
139 return ((CmsSession
) element
).getLocalId();
142 public String
getToolTipText(Object element
) {
143 return getText(element
);
146 new ColumnViewerComparator(column
);
148 viewer
.setInput(WorkbenchUiPlugin
.getDefault().getBundle().getBundleContext());
153 public void setFocus() {
155 viewer
.getControl().setFocus();
158 /** Content provider managing the array of bundles */
159 private static class CmsSessionContentProvider
implements IStructuredContentProvider
{
160 private static final long serialVersionUID
= -8533792785725875977L;
162 public Object
[] getElements(Object inputElement
) {
163 if (inputElement
instanceof BundleContext
) {
164 BundleContext bc
= (BundleContext
) inputElement
;
165 Collection
<ServiceReference
<CmsSession
>> srs
;
167 srs
= bc
.getServiceReferences(CmsSession
.class, null);
168 } catch (InvalidSyntaxException e
) {
169 throw new CmsException("Cannot retrieve CMS sessions", e
);
171 List
<CmsSession
> res
= new ArrayList
<>();
172 for (ServiceReference
<CmsSession
> sr
: srs
) {
173 res
.add(bc
.getService(sr
));
175 return res
.toArray();
180 public void dispose() {
183 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {