Skip to main content
summaryrefslogtreecommitdiffstats
blob: b486bd403050250dfd352356cd08a926bf32f200 (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
/*******************************************************************************
 * 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.ote.ui.define.viewers.actions;

import java.net.URL;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.ote.define.artifacts.ArtifactTestRunOperator;
import org.eclipse.osee.ote.define.artifacts.TestRunOperator;
import org.eclipse.osee.ote.ui.define.OteUiDefinePlugin;
import org.eclipse.osee.ote.ui.define.utilities.SelectionHelper;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;

/**
 * @author Roberto E. Escobar
 */
public class OpenAssociatedScript extends AbstractActionHandler {
   private static final SelectionHelper selectionHelper = SelectionHelper.getInstance();

   public OpenAssociatedScript(StructuredViewer viewer, String text) throws Exception {
      super(viewer, text);
   }

   public OpenAssociatedScript(StructuredViewer viewer, String text, ImageDescriptor image) throws Exception {
      super(viewer, text, image);
   }

   @Override
   public void updateState() {
      TestRunOperator operator = selectionHelper.getSelection(getViewer());
      setEnabled(operator != null);
   }

   @Override
   public void run() {
      try {
         ArtifactTestRunOperator operator = selectionHelper.getSelection(getViewer());
         if (operator.isScriptRevisionValid()) {
            openRemoteScript(operator.getScriptUrl(), operator.getScriptRevision());
         } else {
            handleException();
         }
      } catch (Exception ex) {
         OseeLog.log(OteUiDefinePlugin.class, OseeLevel.SEVERE_POPUP, ex);
      }
   }

   private void handleException() {
      MessageDialog.openError(AWorkbench.getActiveShell(), "Open Script", "Unable to open script with invalid url.");
   }

   private void openRemoteScript(String scriptUrl, String revision) {
      try {
         URL urlToOpen = new URL(scriptUrl);

         IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
         IWebBrowser browser = browserSupport.createBrowser(IWorkbenchBrowserSupport.AS_EDITOR,
            "org.eclipse.ui.browser.editor", scriptUrl, "");
         browser.openURL(urlToOpen);

      } catch (Exception ex) {
         handleException();
      }
   }
}

Back to the top