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;
}
Aggregations