Skip to main content
summaryrefslogtreecommitdiffstats
blob: b0747f840989c4ea824c9dbf0895b92938d0b545 (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*******************************************************************************
 * 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.ats.world;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.nebula.widgets.xviewer.IXViewerFactory;
import org.eclipse.nebula.widgets.xviewer.customize.CustomizeData;
import org.eclipse.osee.ats.actions.OpenNewAtsWorldEditorAction.IOpenNewAtsWorldEditorHandler;
import org.eclipse.osee.ats.actions.OpenNewAtsWorldEditorSelectedAction.IOpenNewAtsWorldEditorSelectedHandler;
import org.eclipse.osee.ats.artifact.AbstractWorkflowArtifact;
import org.eclipse.osee.ats.artifact.ActionArtifact;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.util.AtsUtil;
import org.eclipse.osee.ats.world.search.WorldSearchItem;
import org.eclipse.osee.ats.world.search.WorldSearchItem.SearchType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.DateUtil;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.IATSArtifact;
import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateComposite.TableLoadOption;
import org.eclipse.osee.framework.ui.skynet.action.RefreshAction.IRefreshActionHandler;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.skynet.render.RendererManager;
import org.eclipse.osee.framework.ui.skynet.util.DbConnectionExceptionComposite;
import org.eclipse.osee.framework.ui.swt.ALayout;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * @author Donald G. Dunne
 */
public class WorldComposite extends ScrolledComposite implements IWorldViewerEventHandler, IOpenNewAtsWorldEditorHandler, IOpenNewAtsWorldEditorSelectedHandler, IRefreshActionHandler {

   private final WorldXViewer worldXViewer;
   private final Set<Artifact> worldArts = new HashSet<Artifact>(200);
   private final Set<Artifact> otherArts = new HashSet<Artifact>(200);
   private final IWorldEditor iWorldEditor;

   public WorldComposite(IWorldEditor worldEditor, Composite parent, int style) {
      this(worldEditor, null, parent, style);
   }

   public WorldComposite(IWorldEditor worldEditor, IXViewerFactory xViewerFactory, Composite parent, int style) {
      super(parent, style);
      this.iWorldEditor = worldEditor;

      setLayout(new GridLayout(1, true));
      setLayoutData(new GridData(GridData.FILL_BOTH));

      Composite mainComp = new Composite(this, SWT.NONE);
      mainComp.setLayout(ALayout.getZeroMarginLayout());
      mainComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

      if (!DbConnectionExceptionComposite.dbConnectionIsOk(this)) {
         worldXViewer = null;
         return;
      }

      worldXViewer =
         new WorldXViewer(mainComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION,
            xViewerFactory != null ? xViewerFactory : new WorldXViewerFactory(), null);
      worldXViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));

      worldXViewer.setContentProvider(new WorldContentProvider(worldXViewer));
      worldXViewer.setLabelProvider(new WorldLabelProvider(worldXViewer));

      new WorldViewDragAndDrop(this, WorldEditor.EDITOR_ID);

      setContent(mainComp);
      setExpandHorizontal(true);
      setExpandVertical(true);
      layout();

      WorldXViewerEventManager.add(this);
   }

   public double getManHoursPerDayPreference() throws OseeCoreException {
      if (worldArts.size() > 0) {
         Artifact artifact = worldArts.iterator().next();
         if (artifact instanceof ActionArtifact) {
            artifact = ((ActionArtifact) artifact).getTeamWorkFlowArtifacts().iterator().next();
         }
         return ((AbstractWorkflowArtifact) artifact).getManHrsPerDayPreference();
      }
      return AtsUtil.DEFAULT_HOURS_PER_WORK_DAY;
   }

   public void setCustomizeData(CustomizeData customizeData) {
      worldXViewer.getCustomizeMgr().loadCustomization(customizeData);
   }

   public Control getControl() {
      return worldXViewer.getControl();
   }

   public void load(final String name, final Collection<? extends Artifact> arts, TableLoadOption... tableLoadOption) {
      load(name, arts, null, tableLoadOption);
   }

   public void load(final String name, final Collection<? extends Artifact> arts, final CustomizeData customizeData, TableLoadOption... tableLoadOption) {
      Displays.pendInDisplayThread(new Runnable() {
         @Override
         public void run() {
            worldArts.clear();
            otherArts.clear();
            for (Artifact art : arts) {
               if (art instanceof IATSArtifact) {
                  worldArts.add(art);
               } else {
                  otherArts.add(art);
               }
            }
            if (customizeData != null && !worldXViewer.getCustomizeMgr().generateCustDataFromTable().equals(
               customizeData)) {
               setCustomizeData(customizeData);
            }
            if (arts.isEmpty()) {
               setTableTitle("No Results Found - " + name, true);
            } else {
               setTableTitle(name, false);
            }
            worldXViewer.setInput(worldArts);
            worldXViewer.updateStatusLabel();
            if (otherArts.size() > 0 && MessageDialog.openConfirm(Displays.getActiveShell(),
               "Open in Artifact Editor?",
               otherArts.size() + " Non-WorldView Artifacts were returned from request.\n\nOpen in Artifact Editor?")) {
               RendererManager.openInJob(otherArts, PresentationType.GENERALIZED_EDIT);
            }
            worldXViewer.getTree().setFocus();
         }
      });
      // Need to reflow the managed page based on the results.  Don't put this in the above thread.
      iWorldEditor.reflow();
   }

   public static class FilterLabelProvider implements ILabelProvider {

      @Override
      public Image getImage(Object arg0) {
         return null;
      }

      @Override
      public String getText(Object arg0) {
         try {
            return ((WorldSearchItem) arg0).getSelectedName(SearchType.Search);
         } catch (OseeCoreException ex) {
            return ex.getLocalizedMessage();
         }
      }

      @Override
      public void addListener(ILabelProviderListener arg0) {
         // do nothing
      }

      @Override
      public void dispose() {
         // do nothing
      }

      @Override
      public boolean isLabelProperty(Object arg0, String arg1) {
         return false;
      }

      @Override
      public void removeListener(ILabelProviderListener arg0) {
         // do nothing
      }
   }

   public static class FilterContentProvider implements IStructuredContentProvider {
      @Override
      public Object[] getElements(Object arg0) {
         return ((ArrayList<?>) arg0).toArray();
      }

      @Override
      public void dispose() {
         // do nothing
      }

      @Override
      public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
         // do nothing
      }
   }

   public void setTableTitle(final String title, final boolean warning) {
      Displays.ensureInDisplayThread(new Runnable() {
         @Override
         public void run() {
            iWorldEditor.setTableTitle(title, warning);
            worldXViewer.setReportingTitle(title + " - " + DateUtil.getDateNow());
         };
      });
   }

   public List<Artifact> getLoadedArtifacts() {
      return getXViewer().getLoadedArtifacts();
   }

   public void disposeComposite() {
      if (worldXViewer != null && !worldXViewer.getTree().isDisposed()) {
         worldXViewer.dispose();
      }
      WorldXViewerEventManager.remove(this);
   }

   public WorldXViewer getXViewer() {
      return worldXViewer;
   }

   @Override
   public void refreshActionHandler() {
      try {
         iWorldEditor.reSearch();
      } catch (Exception ex) {
         OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, ex);
      }
   }

   @Override
   public CustomizeData getCustomizeDataCopy() {
      return worldXViewer.getCustomizeMgr().generateCustDataFromTable();
   }

   @Override
   public IWorldEditorProvider getWorldEditorProviderCopy() throws OseeCoreException {
      return iWorldEditor.getWorldEditorProvider().copyProvider();
   }

   @Override
   public List<Artifact> getSelectedArtifacts() {
      return worldXViewer.getSelectedArtifacts();
   }

   @Override
   public void removeItems(Collection<? extends Object> objects) {
      // remove from model
      worldArts.removeAll(objects);
   }

   @Override
   public WorldXViewer getWorldXViewer() {
      return worldXViewer;
   }

   @Override
   public void relationsModifed(Collection<Artifact> relModifiedArts) {
      // provided for subclass implementation
   }

}

Back to the top