Skip to main content
summaryrefslogtreecommitdiffstats
blob: 84419011a7a2a24c9aa5b118a26b5e9fb0868507 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.admin;

import java.util.ArrayList;
import java.util.logging.Level;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.plugin.core.IActionable;
import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
import org.eclipse.osee.framework.skynet.core.event.model.BroadcastEvent;
import org.eclipse.osee.framework.skynet.core.event.model.BroadcastEventType;
import org.eclipse.osee.framework.ui.admin.dbtabletab.DbItem;
import org.eclipse.osee.framework.ui.admin.dbtabletab.DbTableTab;
import org.eclipse.osee.framework.ui.admin.dbtabletab.SiteGssflRpcr;
import org.eclipse.osee.framework.ui.plugin.PluginUiImage;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.widgets.dialog.EntryDialog;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.part.ViewPart;

/**
 * Allows administration of access for OSEE environment <li>Database tables <li>OSEE user permissions
 * 
 * @author Jeff C. Phillips
 */

public class AdminView extends ViewPart implements IActionable {
   public static final String VIEW_ID = "org.eclipse.osee.framework.ui.admin.AdminView";
   private static Action saveAction;
   private TabFolder tabFolder;
   private final ArrayList<DbItem> dbItems;
   private final Cursor handCursor;
   private Composite parentComp;

   public AdminView() {
      dbItems = new ArrayList<DbItem>();
      dbItems.add(new SiteGssflRpcr());
      handCursor = new Cursor(null, SWT.CURSOR_HAND);
   }

   @Override
   public void dispose() {
      super.dispose();
      handCursor.dispose();
   }

   @Override
   public void setFocus() {
      if (parentComp != null) {
         parentComp.setFocus();
      }
   }

   protected void createActions() throws OseeCoreException {

      saveAction = new Action("Save") {
         @Override
         public void run() {
            save();
         }
      };
      saveAction.setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.SAVED));
      saveAction.setToolTipText("Save");

      Action refreshAction = new Action("Refresh") {

         @Override
         public void run() {
            try {
               DbTableTab.refresh();
            } catch (OseeCoreException ex) {
               OseeLog.log(AdminView.class, Level.SEVERE, ex);
            }
         }
      };
      refreshAction.setImageDescriptor(ImageManager.getImageDescriptor(PluginUiImage.REFRESH));
      refreshAction.setToolTipText("Refresh");

      Action broadcastMessage = new Action("Broadcast Message") {

         @Override
         public void run() {
            handleBroadcastMessage();
         }
      };

      broadcastMessage.setToolTipText("Broadcast Message");
      broadcastMessage.setEnabled(AccessControlManager.isOseeAdmin());

      Action pingAction = new Action("Ping OSEE Clients") {

         @Override
         public void run() {
            handlePing();
         }
      };

      pingAction.setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.HELP));
      pingAction.setToolTipText("Ping OSEE Clients");
      pingAction.setEnabled(AccessControlManager.isOseeAdmin());

      IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
      toolbarManager.add(saveAction);
      toolbarManager.add(refreshAction);
      toolbarManager.add(broadcastMessage);
      if (AccessControlManager.isOseeAdmin()) {
         toolbarManager.add(pingAction);
      }
   }

   public void handleBroadcastMessage() {
      EntryDialog ed =
         new EntryDialog(Displays.getActiveShell(), "Broadcast Message to OSEE Instantiations", null, "Enter Message",
            MessageDialog.QUESTION, new String[] {"OK", "Cancel"}, 0);
      if (ed.open() == 0) {
         String message = ed.getEntry();
         if (!message.equals("")) {
            if (MessageDialog.openConfirm(Displays.getActiveShell(), "Broadcast Message",
               "Broadcast message\n\n\"" + message + "\"\n\nAre you sure?")) {
               try {
                  OseeEventManager.kickBroadcastEvent(this, new BroadcastEvent(BroadcastEventType.Message, null,
                     message));
                  AWorkbench.popup("Success", "Message sent.");
               } catch (Exception ex) {
                  OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
               }
            }
         }
      }
   }

   public void handlePing() {
      if (MessageDialog.openConfirm(Displays.getActiveShell(), "Ping OSEE Instantiations?", "Ping OSEE Instantiations?")) {
         try {
            OseeEventManager.kickBroadcastEvent(this, new BroadcastEvent(BroadcastEventType.Ping, null,
               ClientSessionManager.getSession().toString()));
            AWorkbench.popup("Success", "Ping Sent");
         } catch (Exception ex) {
            OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
         }
      }
   }

   /*
    * @see IWorkbenchPart#createPartControl(Composite)
    */
   @Override
   public void createPartControl(Composite parent) {
      try {
         // IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager();
         // slManager.setErrorMessage("error");
         parentComp = parent;

         GridData gridData = new GridData();
         gridData.verticalAlignment = GridData.FILL;
         gridData.horizontalAlignment = GridData.FILL;
         gridData.grabExcessVerticalSpace = true;
         gridData.grabExcessHorizontalSpace = true;

         GridLayout gridLayout = new GridLayout(1, false);
         gridData.heightHint = 1000;
         gridData.widthHint = 1000;
         parent.setLayout(gridLayout);

         tabFolder = new TabFolder(parent, SWT.BORDER);
         tabFolder.setLayoutData(gridData);

         // ModeChecker.check(parent);

         new OseeClientsTab(tabFolder);
         new ClientsStatsTab(tabFolder);
         new DbTableTab(tabFolder);

         parent.layout();

         createActions();
      } catch (Exception ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
      }
   }

   /**
    * handles saving to the database for every tab item
    */
   public void save() {
      // database tab
      if (tabFolder.getSelectionIndex() == 2) {
         DbTableTab.dbTableViewer.save();
         setSaveNeeded(false);
      }
   }

   public static void setSaveNeeded(boolean needed) {

      if (needed) {
         saveAction.setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.SAVE_NEEDED));
      } else {
         saveAction.setImageDescriptor(ImageManager.getImageDescriptor(FrameworkImage.SAVED));
      }
   }

   @Override
   public String getActionDescription() {
      String desc = "";
      TabItem items[] = tabFolder.getSelection();
      if (items.length == 1) {
         String tabName = items[0].getText();
         desc += String.format("Tab = %s ", tabName);
      }
      return desc;
   }

}

Back to the top