package org.eparapher.rcp.actions; import java.io.File; import org.apache.log4j.Logger; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eparapher.core.encryption.CMSEncryption; import org.eparapher.core.encryption.CMSEncryptionParameters; import org.eparapher.core.encryption.DefaultEncryptionParameters; import org.eparapher.core.encryption.GenericCypher; import org.eparapher.core.tools.DefaulteParapherParameters; import org.eparapher.rcp.tools.GUIIcons; import org.eparapher.rcp.tools.RCPGUI; import org.eparapher.rcp.wizards.CMSEncryptionWizard; public class CMSEncryptionAction extends GenericEncryptionAction { private static Logger log = Logger.getLogger(CMSEncryptionAction.class); public CMSEncryptionAction() { super(null, true, "CMS encryption"); } public CMSEncryptionAction(TreeViewer mviewer, boolean museWizard) { super(mviewer, museWizard, "CMS encryption"); } public CMSEncryptionAction(IWorkbenchWindow mwindow) { super(mwindow, "CMS encryption"); } public CMSEncryptionAction(String[] files, boolean museWizard) { super(null, museWizard, "CMS encryption (wizard)"); filesForAction = files; } public void buildAction() { this.setId(this.getClass().getName()); this.setImageDescriptor(GUIIcons.ENCRYPTION_ICON); if (!usewizard) { this.setText("CMS Encryption"); this.setToolTipText("Encrypt your document(s) in CMS format with default parameters"); this.setAccelerator(SWT.CTRL | 'E'); } else { this.setText("CMS Encryption (wizard)"); this.setToolTipText("Encrypt your document(s) in CMS format using a wizard"); this.setAccelerator(SWT.CTRL | 'R'); } } @Override DefaulteParapherParameters getParameters() { CMSEncryptionParameters cmsencparams = new CMSEncryptionParameters(); cmsencparams.setCMSEncryptionParamsFromPreferences(); if (viewer != null) cmsencparams.setFileSelection(getFileSelectionFromView()); if (filesForAction != null) cmsencparams.setFileSelection(getFileSelectionFromParameters()); if (usewizard) { //Launch Wizard to get CMS encryption Parameters CMSEncryptionWizard cmsEncWizard = new CMSEncryptionWizard(cmsencparams); if (window==null) window=PlatformUI.getWorkbench().getActiveWorkbenchWindow(); WizardDialog dialog = new WizardDialog(window.getShell(), cmsEncWizard); try { if ( dialog.open() != Window.OK ) { log.info("CMS encryption wizard cancelled"); return null; } } catch (Exception e) { log.debug("Problem while invoking the CMS Settings Signature Wizard",e); } //recover params from wizard cmsencparams = cmsEncWizard.getCMSEncryptionParams(); } return cmsencparams; } protected GenericCypher getCypher() { return new CMSEncryption(); } @Override boolean isFileWithCorrectFormat(File file2verify) { return true; } @Override void preencryption(IProgressMonitor monitor, GenericCypher cipher, DefaultEncryptionParameters encparams) { } @Override void encryptFile(IProgressMonitor monitor, File file, GenericCypher cipher, DefaultEncryptionParameters encparams) { monitor.subTask("Encrypting "+file.getName()); cipher.encrypt(file.getAbsolutePath(), encparams); monitor.worked(1); } @Override void postencryption(IProgressMonitor monitor, GenericCypher cipher, DefaultEncryptionParameters encparams) { } }