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
.e4
.monitoring
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collection
;
23 import java
.util
.List
;
25 import javax
.annotation
.PostConstruct
;
26 import javax
.naming
.ldap
.LdapName
;
28 import org
.argeo
.cms
.CmsException
;
29 import org
.argeo
.cms
.auth
.CmsSession
;
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
.e4
.ui
.di
.Focus
;
34 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
35 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
36 import org
.eclipse
.jface
.viewers
.TableViewer
;
37 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
38 import org
.eclipse
.jface
.viewers
.Viewer
;
39 import org
.eclipse
.swt
.SWT
;
40 import org
.eclipse
.swt
.widgets
.Composite
;
41 import org
.osgi
.framework
.BundleContext
;
42 import org
.osgi
.framework
.FrameworkUtil
;
43 import org
.osgi
.framework
.InvalidSyntaxException
;
44 import org
.osgi
.framework
.ServiceReference
;
47 * Overview of the active CMS sessions.
49 public class CmsSessionsView
{
50 private final static BundleContext bc
= FrameworkUtil
.getBundle(CmsSessionsView
.class).getBundleContext();
52 private TableViewer viewer
;
55 public void createPartControl(Composite parent
) {
56 viewer
= new TableViewer(parent
);
57 viewer
.setContentProvider(new CmsSessionContentProvider());
58 viewer
.getTable().setHeaderVisible(true);
60 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
62 int longColWidth
= 150;
63 int smallColWidth
= 100;
66 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
67 column
.getColumn().setWidth(longColWidth
);
68 column
.getColumn().setText("User");
69 column
.setLabelProvider(new ColumnLabelProvider() {
70 private static final long serialVersionUID
= -5234573509093747505L;
72 public String
getText(Object element
) {
73 return ((CmsSession
) element
).getAuthorization().toString();
76 public String
getToolTipText(Object element
) {
77 return ((CmsSession
) element
).getUserDn().toString();
80 new ColumnViewerComparator(column
);
83 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
84 column
.getColumn().setWidth(smallColWidth
);
85 column
.getColumn().setText("Since");
86 column
.setLabelProvider(new ColumnLabelProvider() {
87 private static final long serialVersionUID
= -5234573509093747505L;
89 public String
getText(Object element
) {
90 return LangUtils
.since(((CmsSession
) element
).getCreationTime());
93 public String
getToolTipText(Object element
) {
94 return ((CmsSession
) element
).getCreationTime().toString();
97 new ColumnViewerComparator(column
);
100 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
101 column
.getColumn().setWidth(smallColWidth
);
102 column
.getColumn().setText("Username");
103 column
.setLabelProvider(new ColumnLabelProvider() {
104 private static final long serialVersionUID
= -5234573509093747505L;
106 public String
getText(Object element
) {
107 LdapName userDn
= ((CmsSession
) element
).getUserDn();
108 return userDn
.getRdn(userDn
.size() - 1).getValue().toString();
111 public String
getToolTipText(Object element
) {
112 return ((CmsSession
) element
).getUserDn().toString();
115 new ColumnViewerComparator(column
);
118 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
119 column
.getColumn().setWidth(smallColWidth
);
120 column
.getColumn().setText("UUID");
121 column
.setLabelProvider(new ColumnLabelProvider() {
122 private static final long serialVersionUID
= -5234573509093747505L;
124 public String
getText(Object element
) {
125 return ((CmsSession
) element
).getUuid().toString();
128 public String
getToolTipText(Object element
) {
129 return getText(element
);
132 new ColumnViewerComparator(column
);
135 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
136 column
.getColumn().setWidth(smallColWidth
);
137 column
.getColumn().setText("Local ID");
138 column
.setLabelProvider(new ColumnLabelProvider() {
139 private static final long serialVersionUID
= -5234573509093747505L;
141 public String
getText(Object element
) {
142 return ((CmsSession
) element
).getLocalId();
145 public String
getToolTipText(Object element
) {
146 return getText(element
);
149 new ColumnViewerComparator(column
);
156 public void setFocus() {
158 viewer
.getControl().setFocus();
161 /** Content provider managing the array of bundles */
162 private static class CmsSessionContentProvider
implements IStructuredContentProvider
{
163 private static final long serialVersionUID
= -8533792785725875977L;
165 public Object
[] getElements(Object inputElement
) {
166 if (inputElement
instanceof BundleContext
) {
167 BundleContext bc
= (BundleContext
) inputElement
;
168 Collection
<ServiceReference
<CmsSession
>> srs
;
170 srs
= bc
.getServiceReferences(CmsSession
.class, null);
171 } catch (InvalidSyntaxException e
) {
172 throw new CmsException("Cannot retrieve CMS sessions", e
);
174 List
<CmsSession
> res
= new ArrayList
<>();
175 for (ServiceReference
<CmsSession
> sr
: srs
) {
176 res
.add(bc
.getService(sr
));
178 return res
.toArray();
183 public void dispose() {
186 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {