Modify pom file
[nemo.git] / nemo-tools / eclipse-plugin-project / nemo-rest / org.opendaylight.nemo.tool.eclipse.plugin.rest / src / org / opendaylight / nemo / tool / eclipse / plugin / rest / actions / NemoAction.java
1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions;
2
3 import java.io.IOException;
4
5 import org.apache.http.client.ClientProtocolException;
6 import org.apache.http.client.HttpClient;
7 import org.apache.http.client.methods.HttpPost;
8 import org.apache.http.impl.client.DefaultHttpClient;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.jface.viewers.ISelection;
11 import org.eclipse.ui.IWorkbenchWindow;
12 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
13 import org.opendaylight.nemo.tool.eclipse.plugin.rest.collectinfo.GetContent;
14 import org.eclipse.jface.dialogs.MessageDialog;
15
16 /**
17  * Our sample action implements workbench action delegate. The action proxy will
18  * be created by the workbench and shown in the UI. When the user tries to use
19  * the action, this delegate will be created and execution will be delegated to
20  * it.
21  *
22  * @see IWorkbenchWindowActionDelegate
23  */
24 public class NemoAction implements IWorkbenchWindowActionDelegate {
25         private IWorkbenchWindow window;
26
27         /**
28          * The constructor.
29          */
30         public NemoAction() {
31         }
32
33         /**
34          * The action has been activated. The argument of the method represents the
35          * 'real' action sitting in the workbench UI.
36          *
37          * @see IWorkbenchWindowActionDelegate#run
38          */
39         public void run(IAction action) {
40                 String content = GetContent.activeContent();
41                 NemoParserImpl2 parserImpl = new NemoParserImpl2();
42                 parserImpl.format(content);
43                 boolean en = parserImpl.findRest();
44                 if (!en) {
45              showDialog("Please add engine info.");
46                 }else{
47                         boolean us = parserImpl.findUser();
48                         if(!us){
49                                 showDialog("Please add user info.");
50                         }else{
51                                 boolean result = parserImpl.send();
52                                 showDialog(parserImpl.getErrorInfo()+"\r\n"+parserImpl.getKeepResult());
53                         }
54                 }
55
56         }
57
58         private void showDialog(String log) {
59                 MessageDialog.openInformation(window.getShell(), "Run", log);
60         }
61
62         /**
63          * Selection in the workbench has been changed. We can change the state of
64          * the 'real' action here if we want, but this can only happen after the
65          * delegate has been created.
66          *
67          * @see IWorkbenchWindowActionDelegate#selectionChanged
68          */
69         public void selectionChanged(IAction action, ISelection selection) {
70         }
71
72         /**
73          * We can use this method to dispose of any system resources we previously
74          * allocated.
75          *
76          * @see IWorkbenchWindowActionDelegate#dispose
77          */
78         public void dispose() {
79         }
80
81         /**
82          * We will cache window object in order to be able to provide parent shell
83          * for the message dialog.
84          *
85          * @see IWorkbenchWindowActionDelegate#init
86          */
87         public void init(IWorkbenchWindow window) {
88                 this.window = window;
89         }
90 }