Thursday, November 13, 2008

Print your Gef Editor

Here the Code to print your Gef Editor



Create an Action Method In your configureGraphicalViewer and override a run method….


In the run () Method implements the following Code….



int style = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getStyle();

Shell shell = new Shell ((style & SWT.MIRRORED)! =0? SWT.RIGHT_TO_LEFT:SWT.NONE);

PrintDialog dialog = new PrintDialog(shell,SWT.NULL);

PrinterData data = dialog.open();

if(data != null)

{

PrintGraphicalViewerOperation operation = new PrintGraphicalViewerOperation(new Printer(data),getGraphicalViewer());

// here you can set the Print Mode

operation.setPrintMode(2);

operation.run("Printing Gef");

}


//Set the Text and register that to your toolbar….

printAction.setText("Print");

getEditorSite().getActionBars().getToolBarManager().add(printAction);



Now you can see a Print Button on the Toolbar as shown in the image....




Once you click the Print Button on the Toolbar… Print Dialog will open then your can select the printer and Click Print to print your editor Content....

Regards,

Karthikeyan

0 comments: