Skip to main content
summaryrefslogtreecommitdiffstats
blob: a29ad924a3de0a8eac1a144ad0c8e2a09b514c52 (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
/*******************************************************************************
 * 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.actions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.osee.ats.AtsImage;
import org.eclipse.osee.ats.actions.wizard.NewNoteWizard;
import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition;
import org.eclipse.osee.ats.core.client.workflow.AbstractWorkflowArtifact;
import org.eclipse.osee.ats.core.client.workflow.note.NoteType;
import org.eclipse.osee.ats.internal.AtsClientService;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.ui.swt.IDirtiableEditor;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.ui.PlatformUI;

/**
 * @author Donald G. Dunne
 */
public class AddNoteAction extends AbstractAtsAction {

   private final AbstractWorkflowArtifact sma;
   private final IDirtiableEditor dirtiable;
   private boolean emulate = false;
   private String selectedState;
   private NoteType noteType;
   private String noteText;

   public AddNoteAction(AbstractWorkflowArtifact sma, IDirtiableEditor dirtiable) {
      super();
      this.sma = sma;
      this.dirtiable = dirtiable;
      setText("Add Note");
      setToolTipText(getText());
   }

   @Override
   public void runWithException() throws OseeCoreException {
      ArrayList<String> artifactNames = new ArrayList<String>();
      Map<String, String> selectedToStateName = new HashMap<String, String>();
      artifactNames.add("Whole \"" + sma.getArtifactTypeName() + "\"");
      for (IAtsStateDefinition stateDefinition : AtsClientService.get().getWorkDefinitionAdmin().getStatesOrderedByOrdinal(
         sma.getWorkDefinition())) {
         String displayName = "\"" + stateDefinition.getName() + "\" State";
         artifactNames.add(displayName);
         selectedToStateName.put(displayName, stateDefinition.getName());
      }

      if (emulate) {
         boolean result = performEmulate();
         if (!result) {
            return;
         }
      } else {
         boolean result = performUi(artifactNames);
         if (!result) {
            return;
         }
      }
      String state = "";
      if (!selectedState.startsWith(sma.getName() + " - ")) {
         state = selectedToStateName.get(selectedState);
      }
      sma.getNotes().addNote(noteType, state, noteText, AtsClientService.get().getUserService().getCurrentUser());
      dirtiable.onDirtied();
   }

   private boolean performEmulate() {
      this.selectedState = "Endorse";
      this.noteType = NoteType.Comment;
      this.noteText = "this is the comment";
      return true;
   }

   private boolean performUi(ArrayList<String> artifactNames) throws OseeArgumentException {
      NewNoteWizard noteWizard = new NewNoteWizard(artifactNames);
      WizardDialog dialog =
         new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), noteWizard);
      dialog.create();
      if (dialog.open() == 0) {
         selectedState = noteWizard.mainPage.artifactList.getSelected().iterator().next().getName();
         noteType = NoteType.getType(noteWizard.mainPage.typeList.getSelected().iterator().next().getName());
         noteText = noteWizard.mainPage.noteText.get();
         return true;
      }
      return false;
   }

   @Override
   public ImageDescriptor getImageDescriptor() {
      return ImageManager.getImageDescriptor(AtsImage.NEW_NOTE);
   }

   public void setEmulateUi(boolean emulate) {
      this.emulate = emulate;
   }

}

Back to the top