Skip to main content
summaryrefslogtreecommitdiffstats
blob: b057d25e1018bbadd8d9743b2e0f55b611b88da0 (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
/*******************************************************************************
 * Copyright (c) 2010 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.core.dsl.ui.integration;

import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.DEFAULT_OPEN;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERALIZED_EDIT;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.PRODUCE_ATTRIBUTE;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.SPECIALIZED_EDIT;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.dsl.ui.integration.internal.DslUiIntegrationConstants;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.operation.IOperation;
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.types.IArtifact;
import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer;
import org.eclipse.osee.framework.ui.skynet.render.FileSystemRenderer;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

/**
 * @author Jonathan E. Jensen
 */
public abstract class AbstractDslRenderer extends FileSystemRenderer {

   protected static final String COMMAND_ID = "org.eclipse.osee.framework.ui.skynet.render.dsl.editor.command";

   protected AbstractDslRenderer() {
      super();
   }

   /**
    * Simple String name of the renderer
    */
   @Override
   public abstract String getName();

   /**
    * Provides an instance of the concrete class.
    */
   @Override
   public abstract DefaultArtifactRenderer newInstance();

   /**
    * Provides a list of the artifact types that the renderer supports.
    * 
    * @return a list of the artifact types that the renderer supports
    */
   protected abstract IArtifactType[] getArtifactTypeMatches();

   /**
    * Provides the command ID associated with this renderer and adds it to the commandGroup.
    */
   @Override
   public List<String> getCommandIds(CommandGroup commandGroup) {
      ArrayList<String> commandIds = new ArrayList<String>(1);
      if (commandGroup.isEdit()) {
         commandIds.add(COMMAND_ID);
      }

      return commandIds;
   }

   /**
    * Get the file extention associated with the dsl and related artifact.
    */
   @Override
   public abstract String getAssociatedExtension(Artifact artifact) throws OseeCoreException;

   /**
    * Provides a render input stream for the given input.
    */
   @Override
   public abstract InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException;

   /**
    * Provides the update operation for the renderer.
    */
   @Override
   protected abstract IOperation getUpdateOperation(File file, List<Artifact> artifacts, IOseeBranch branch, PresentationType presentationType);

   /**
    * Provides the minimum match ranking for this renderer.
    */
   @Override
   public abstract int minimumRanking();

   /**
    * This function can be overridden if the subclass does not support compare
    */
   @Override
   public boolean supportsCompare() {
      return true;
   }

   @Override
   public int getApplicabilityRating(PresentationType presentationType, IArtifact artifact) throws OseeCoreException {
      Artifact aArtifact = artifact.getFullArtifact();
      if (!presentationType.matches(GENERALIZED_EDIT, PRODUCE_ATTRIBUTE) && !aArtifact.isHistorical()) {
         if (aArtifact.isOfType(getArtifactTypeMatches())) {
            return ARTIFACT_TYPE_MATCH;
         }
      }
      return NO_MATCH;
   }

   @SuppressWarnings("unused")
   @Override
   public final void open(final List<Artifact> artifacts, final PresentationType presentationType) throws OseeCoreException {

      Displays.ensureInDisplayThread(new Runnable() {
         @Override
         public void run() {
            if (!artifacts.isEmpty()) {
               try {
                  PresentationType onOpenPresentationType = getOnOpenPresentationType(presentationType);
                  IFile file = renderToFile(artifacts, onOpenPresentationType);
                  if (file != null) {
                     IWorkbench workbench = PlatformUI.getWorkbench();
                     IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                     IDE.openEditor(page, file);
                  }
               } catch (CoreException ex) {
                  OseeLog.log(DslUiIntegrationConstants.class, OseeLevel.SEVERE_POPUP, ex);
               }
            }
         }
      });
   }

   public PresentationType getOnOpenPresentationType(PresentationType presentationType) {
      return presentationType == DEFAULT_OPEN ? SPECIALIZED_EDIT : presentationType;
   }

   /**
    * This is required by the base class but not by this renderer. Therefore, we stub it out.
    */
   @Override
   public final Program getAssociatedProgram(Artifact artifact) throws OseeCoreException {
      throw new OseeCoreException("should not be called");
   }
}

Back to the top