package org.eparapher.rcp.tools; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import org.apache.log4j.Logger; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IPerspectiveDescriptor; import org.eclipse.ui.IPerspectiveRegistry; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.statushandlers.StatusManager; import org.eparapher.core.EParapherManager; import org.eparapher.core.tools.FileUtil; import org.eparapher.rcp.Application; public class eParapherTools { private static Logger log = Logger.getLogger(eParapherTools.class); public static Image getPluginImage(String filePath) { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); if (is==null) return null; else return new Image(null,is); } public static void createGUILine(Composite parent, int ncol) { Label line = new Label(parent, SWT.SEPARATOR|SWT.HORIZONTAL|SWT.BOLD); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = ncol; line.setLayoutData(gridData); } public static void errorMessage(String message) { IStatus status = new Status(IStatus.ERROR,Application.PLUGIN_ID, message); StatusManager.getManager().handle(status, StatusManager.SHOW); } //public static void statusLineMessage(String message) { //IStatusLineManager slmgr = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorSite().getActionBars().getStatusLineManager(); //if (slmgr!=null) // slmgr.setMessage(message); //} public static boolean showPrefGUI(String id, String[] displayedIds) { PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, id, displayedIds, null); if ( dialog.open() != Window.OK ) return false; return true; } public static String [] getLabel4Combo(String[][] Families) { String[] labels = new String[Families.length]; for (int i = 0; i < Families.length; i++) labels[i] = Families[i][0]; return labels; } public static boolean createSignatureImage() { File img = new File( EParapherManager.getInstance().getSettings().getPDFSignatureImage()); if ( !img.exists() ) { log.debug("Default PDF Signature image created in : " + img.getAbsolutePath() ); URL url = Platform.getBundle( Application.PLUGIN_ID ).getResource( "defaultpdfsignature.png" ); try { InputStream is = url.openStream(); FileUtil.writeToFile(img.getAbsolutePath(), is, true); } catch (IOException e) { log.error("Error while copying signature image " + img.getAbsolutePath(),e ); } catch (Throwable e) { log.error("Error while copying signature image " + img.getAbsolutePath(),e ); } } return true; } /** * Show all perspective icons */ public void showAllPerspectives(IWorkbenchWindowConfigurer configurer) { if (Boolean.TRUE.equals(configurer.getData("restored"))) return; IWorkbenchPage page = configurer.getWindow().getActivePage(); if (page != null) { IPerspectiveDescriptor activePersp = page.getPerspective(); // close default perspective page.closePerspective(activePersp, true, false); IPerspectiveRegistry reg = configurer.getWorkbenchConfigurer() .getWorkbench().getPerspectiveRegistry(); IPerspectiveDescriptor[] perpectives = reg.getPerspectives(); for (int i = 0; i < perpectives.length; i++) { IPerspectiveDescriptor desc = perpectives[i]; page.setPerspective(desc); } } } }