Project

General

Profile

Download (6.33 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.user.view;
12

    
13
import java.util.List;
14

    
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jface.action.GroupMarker;
17
import org.eclipse.jface.action.MenuManager;
18
import org.eclipse.jface.viewers.TableViewer;
19
import org.eclipse.jface.viewers.TableViewerColumn;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.FocusAdapter;
22
import org.eclipse.swt.events.FocusEvent;
23
import org.eclipse.swt.layout.FillLayout;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Menu;
27
import org.eclipse.swt.widgets.Table;
28
import org.eclipse.ui.IMemento;
29
import org.eclipse.ui.IWorkbenchActionConstants;
30
import org.eclipse.ui.part.ViewPart;
31

    
32
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
33
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
34
import eu.etaxonomy.cdm.model.common.CdmBase;
35
import eu.etaxonomy.cdm.model.common.User;
36
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
37
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
38
import eu.etaxonomy.taxeditor.model.IContextListener;
39
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
40
import eu.etaxonomy.taxeditor.store.CdmStore;
41

    
42
/**
43
 * <p>UserManagerView class.</p>
44
 *
45
 * @author n.hoffmann
46
 * @created 01.07.2009
47
 * @version 1.0
48
 */
49
public class UserManagerView extends ViewPart implements IConversationEnabled, IPostOperationEnabled{
50
	
51
	private class ContextListener extends ContextListenerAdapter{
52

    
53
		/* (non-Javadoc)
54
		 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
55
		 */
56
		@Override
57
		public void contextStop(IMemento memento, IProgressMonitor monitor) {
58
			tableViewer.setInput(null);
59
		}
60

    
61
		/* (non-Javadoc)
62
		 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
63
		 */
64
		@Override
65
		public void contextStart(IMemento memento, IProgressMonitor monitor) {
66
			tableViewer.setInput(getAllUser());
67
		}
68
	}
69
	
70
	/** Constant <code>ID="eu.etaxonomy.taxeditor.store.userManage"{trunked}</code> */
71
	public static String ID = "eu.etaxonomy.taxeditor.store.userManagerView";
72
	
73
	private TableViewer tableViewer;
74

    
75
	private ConversationHolder conversation;
76

    
77
	private IContextListener contextListener;
78

    
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
81
	 */
82
	/** {@inheritDoc} */
83
	@Override
84
	public void createPartControl(Composite parent) {
85
		contextListener = new ContextListener();
86
		CdmStore.getContextManager().addContextListener(contextListener);
87
		
88
		FillLayout fillLayout = new FillLayout();
89
		fillLayout.marginWidth = 0;
90
		fillLayout.marginHeight = 0;
91
		fillLayout.type = SWT.VERTICAL;	
92
		parent.setLayout(fillLayout);
93
		
94
		tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
95
				| SWT.V_SCROLL | SWT.FULL_SELECTION);
96
		
97
		getSite().setSelectionProvider(tableViewer);
98
		
99
		createColumns(tableViewer);
100
		
101
		MenuManager menuMgr = new MenuManager();
102
		menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
103
		getSite().registerContextMenu(menuMgr, tableViewer);
104

    
105
		Control control = tableViewer.getControl();
106
		Menu menu = menuMgr.createContextMenu(control);
107
		control.setMenu(menu);	
108
		
109
		tableViewer.setContentProvider(new UserManagerContentProvider());
110
		tableViewer.setLabelProvider(new UserManagerLabelProvider());
111
				
112
		if(CdmStore.isActive()){
113
			tableViewer.setInput(getAllUser());
114
		}
115
		
116
		
117
		this.addListenerObject(new FocusAdapter() {
118
			/* (non-Javadoc)
119
			 * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent)
120
			 */
121
			@Override
122
			public void focusGained(FocusEvent e) {
123
				super.focusGained(e);
124
				conversation.bind();
125
				tableViewer.getControl().setFocus();
126
			}
127
		});
128
	}
129

    
130
	// This will create the columns for the table
131
	private void createColumns(TableViewer viewer) {
132
		Table table = viewer.getTable();
133
		String[] titles = {"Active", "Name", "Enabled", "Locked", "Person", "Email"};
134
		int[] bounds = { 20, 200, 50, 50, 200, 100};
135

    
136
		for (int i = 0; i < titles.length; i++) {
137
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
138
			column.getColumn().setText(titles[i]);
139
			column.getColumn().setWidth(bounds[i]);
140
			column.getColumn().setResizable(true);
141
			column.getColumn().setMoveable(true);
142
		}
143
		table.setHeaderVisible(true);
144
		table.setLinesVisible(true);
145
	}
146
	
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
149
	 */
150
	/** {@inheritDoc} */
151
	@Override
152
	public void setFocus() {
153
		if(conversation != null){
154
			conversation.bind();
155
		}
156
		tableViewer.getControl().setFocus();
157
	}
158

    
159
	
160
	
161
	/* (non-Javadoc)
162
	 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
163
	 */
164
	/** {@inheritDoc} */
165
	public boolean postOperation(CdmBase objectAffectedByOperation) {
166
		if(CdmStore.isActive()){
167
			List<User> allUsers = getAllUser();
168
			
169
			tableViewer.setInput(allUsers);
170
			tableViewer.refresh();
171
		}
172
		
173
		return true;
174
	}
175
	
176
	/**
177
	 * 
178
	 * @return
179
	 */
180
	private List<User> getAllUser(){
181
		conversation = CdmStore.createConversation();
182
		return CdmStore.getUserService().list(null, null, null, null, null);
183
	}
184

    
185
	/* (non-Javadoc)
186
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
187
	 */
188
	/**
189
	 * <p>getConversationHolder</p>
190
	 *
191
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
192
	 */
193
	public ConversationHolder getConversationHolder() {
194
		return conversation;
195
	}
196

    
197
	/* (non-Javadoc)
198
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
199
	 */
200
	/** {@inheritDoc} */
201
	public void update(CdmDataChangeMap changeEvents) {
202
		// data changes can only be generate here at the moment
203
	}
204

    
205
	/** {@inheritDoc} */
206
	@Override
207
	public void dispose() {
208
		CdmStore.getContextManager().removeContextListener(contextListener);
209
		super.dispose();
210
	}
211

    
212
	/**
213
	 * <p>onComplete</p>
214
	 *
215
	 * @return a boolean.
216
	 */
217
	public boolean onComplete() {
218
		return true;
219
	}
220

    
221

    
222
	
223
}
(3-3/3)