Sunday 23 October 2016

RichClient- call URL - TRIGGER_WithoutButton

plugin.xml
<?xml version="1.0" encoding="UTF-8"?>

<?eclipse version="3.4"?>

<plugin>



   <extension

         point="org.eclipse.ui.commands">
      <command

            name="Sample Command"

            id="MITRIGGER.commands.sampleCommand">

      </command>

   </extension>

   <extension

         point="org.eclipse.ui.handlers">

      <handler

            commandId="MITRIGGER.commands.sampleCommand"

            class="mitrigger.handlers.SampleHandler">

      </handler>

   </extension>

  

   <extension

         point="org.eclipse.ui.menus">

      <menuContribution

            locationURI="menu:org.eclipse.ui.main.menu?after=additions">

         <menu

               label="Sample Menu"

            

               id="MITRIGGER.menus.sampleMenu">

            <command

                  commandId="MITRIGGER.commands.sampleCommand"

                

                  id="MITRIGGER.menus.sampleCommand">

            </command>

         </menu>

      </menuContribution>

    

    

      <menuContribution

            locationURI="toolbar:navigator_Toolbar?after=navigator_Toolbar1">

        

            <command

                  commandId="MITRIGGER.commands.sampleCommand"

                  icon="icons/cube.gif"

                  tooltip="MI-Call"

                  id="MITRIGGER.toolbars.sampleCommand">

            </command>

      

      </menuContribution>   

    

    

   </extension>

  

   <extension point="org.eclipse.ui.views">

      <view

         name="MI-CALL"

         class="mitrigger.view.CustomView"

         id="mitrigger.view.CustomView">

      </view>

   </extension>



</plugin>



MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MITRIGGER
Bundle-SymbolicName: MITRIGGER; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: mitrigger.Activator
Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

CustomeView.java
package mitrigger.view;
/**********************************************************************************************************************
 * Project Description : 1) Provide Custom icon in Manufacturing Process Planner Perspective.
 * 2) Click Action on Custom icon will show Custom view which look like 
 *
 * ________________________________________________________________
 * | |
 * | LabelName_1              TextBox_1 |
 * | |
 * | LabelName_2              TextBox_2 |
 * | |
 * | ----------------- ----------------- |
 * | | Button_Identify| |  Button_Cancel | |
 * | ------------------ ----------------- |
 * |_______________________________________________________________|
 *
 * 3) Click Action on Button_Identify will call some URL to get string name of EBOM line which we needs to highlight 
 *                       
************************************************************************************************************************/
import miconnect.JavaUrlConnectionReader; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart;
public class CustomView extends ViewPart {
/** ID corresponding to the RCP declaration */     public static final String ID = CustomView.class.getName();         Label kitlabel;     Text kittxt;     Label installationlabel;     Text installationtxt;     public CustomView() { super(); } private ISelectionListener listener = new ISelectionListener() { public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) { // we ignore our own selections
if (sourcepart != CustomView.this) {
   showSelection(sourcepart, selection);
}
}
};
public void showSelection(IWorkbenchPart sourcepart, ISelection selection) {
//setContentDescription(sourcepart.getTitle() + " (" + selection.getClass().getName() + ")");
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
showItems(ss.toArray()); } }
  private void showItems(Object[] items) {

System.out.println("items.length ="+items.length);
   for(int i = 0 ; i < items.length; i++){
   System.out.println("My selected object "+ items[i].toString());
}
if(items.length>0) kittxt.setText(items[0].toString());
//tableviewer.setInput(items);
//pagebook.showPage(tableviewer.getControl());
}
@Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub parent.setLayout(new GridLayout(4, false));
//GUI Component Definition Starts 
//1st Row //Label Definition  //kitlabel = new Label(parent, SWT.NONE); //kitlabel.setText("Kit"); //Text Field  Definition with its formating with grid data  //GridData gridDatakit = new GridData(GridData.FILL_HORIZONTAL); //gridDatakit.horizontalSpan = 2; //gridDatakit.grabExcessHorizontalSpace = true;
//kittxt = new Text( parent, SWT.READ_ONLY|SWT.SINGLE | SWT.BORDER );
//To change background colour use kittxt.setBackground(parent.getDisplay().getSystemColor( SWT.COLOR_WHITE ));  //kittxt.setBackground(parent.getDisplay().getSystemColor( SWT.COLOR_WHITE )); //kittxt.setLayoutData(gridDatakit);
//new Label(parent, SWT.NULL);
// 2nd row.
//Label Definition  installationlabel = new Label(parent, SWT.NONE); installationlabel.setText("URL Output");
//Text Field  Definition with its formating with grid data
GridData gridDatainstallation = new GridData(GridData.FILL_HORIZONTAL); gridDatainstallation.horizontalSpan = 2; gridDatainstallation.grabExcessHorizontalSpace = true;
installationtxt = new Text( parent,SWT.MULTI | SWT.BORDER | SWT.H_SCROLL
       | SWT.V_SCROLL); installationtxt.setLayoutData(gridDatainstallation);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
   gridData.horizontalSpan = 3;    gridData.grabExcessVerticalSpace = true;    installationtxt.setLayoutData(gridData); Label labelEmpty = new Label(parent, SWT.NULL);    labelEmpty.setText("                             ");    // last row.    new Label(parent, SWT.NULL); // kittxt.setText( "Readonly Data");
//Add Listner 
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener); //Get Manufacturing Process Planner(MPP) EBOM window
System.out.println("Perspective id is "+getSite().getPage().getPerspective().getId());
System.out.println("Perspective name is "+getSite().getPage().getPerspective().getLabel());
System.out.println("Perspective Description is "+getSite().getPage().getPerspective().getDescription());
JavaUrlConnectionReader miconnobj=new JavaUrlConnectionReader();
String mioutput =miconnobj.getUrlContents("http://www.java-samples.com/j2me/");
System.out.println("mioutput="+mioutput);
installationtxt.setText(mioutput); }
public void dispose() { // important: We need do unregister our listener when the view is disposed
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(listener);
super.dispose();
}
 @Override
 public void setFocus() {
  // TODO Auto-generated method stub
  
 }
}
Sample Handeler
package mitrigger.handlers;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection;
/**
 * Our sample handler extends AbstractHandler, an IHandler base class.  * @see org.eclipse.core.commands.IHandler  * @see org.eclipse.core.commands.AbstractHandler  */ public class SampleHandler extends AbstractHandler { /** * The constructor. */ public SampleHandler() { }
/** * the command has been executed, so extract extract the needed information * from the application context. */ public Object execute(ExecutionEvent event) throws ExecutionException { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("mitrigger.view.CustomView"); } catch (PartInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }

2 comments:

  1. Hi Anil,
    Please create and upload the Eclipse Project here. It will Help.

    ReplyDelete
  2. Hi Gopal,
    Thanks for suggestion.
    I will do that soon.

    ReplyDelete