Search in sources :

Example 1 with ConversionWizardDialog

use of net.heartsome.cat.convert.ui.wizard.ConversionWizardDialog in project translationstudio8 by heartsome.

the class ConversionHandler method execute.

/**
	 * the command has been executed, so extract extract the needed information from the application context.
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    String commandId = event.getCommand().getId();
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection.isEmpty()) {
        return null;
    }
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
        Object object = structuredSelection.getFirstElement();
        // 通过 adapter manager 获得 conversion item
        Object adapter = Platform.getAdapterManager().getAdapter(object, IConversionItem.class);
        if (adapter instanceof IConversionItem) {
            // open the config conversion dialog
            ConverterViewModel converterViewModel = null;
            IConversionItem sourceItem = (IConversionItem) adapter;
            if (commandId.equals("net.heartsome.cat.convert.ui.commands.convertCommand")) {
                converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_POSITIVE);
                // 记住所选择的文件
                converterViewModel.setConversionItem(sourceItem);
                IWizard wizard = new ConversionWizard(Arrays.asList(converterViewModel), null);
                TSWizardDialog dialog = new ConversionWizardDialog(window.getShell(), wizard);
                int result = dialog.open();
                if (result == IDialogConstants.OK_ID) {
                    converterViewModel.convert();
                }
            } else {
                converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_REVERSE);
                converterViewModel.setConversionItem(sourceItem);
                IWizard wizard = new ReverseConversionWizard(Arrays.asList(converterViewModel), null);
                TSWizardDialog dialog = new ConversionWizardDialog(window.getShell(), wizard);
                int result = dialog.open();
                if (result == IDialogConstants.OK_ID) {
                    converterViewModel.convert();
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ReverseConversionWizard(net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard) ConversionWizard(net.heartsome.cat.convert.ui.wizard.ConversionWizard) IWizard(org.eclipse.jface.wizard.IWizard) ConversionWizardDialog(net.heartsome.cat.convert.ui.wizard.ConversionWizardDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ReverseConversionWizard(net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard) ISelection(org.eclipse.jface.viewers.ISelection) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Aggregations

TSWizardDialog (net.heartsome.cat.common.ui.wizard.TSWizardDialog)1 ConverterViewModel (net.heartsome.cat.convert.ui.model.ConverterViewModel)1 IConversionItem (net.heartsome.cat.convert.ui.model.IConversionItem)1 ConversionWizard (net.heartsome.cat.convert.ui.wizard.ConversionWizard)1 ConversionWizardDialog (net.heartsome.cat.convert.ui.wizard.ConversionWizardDialog)1 ReverseConversionWizard (net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWizard (org.eclipse.jface.wizard.IWizard)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1