use of net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard in project translationstudio8 by heartsome.
the class OpenReverseConversionDialogHandler method execute.
public Object execute(ExecutionEvent event, List<IFile> list) {
if (list == null || list.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle1"), Messages.getString("handler.OpenReverseConversionDialogHandler.msg1"));
return null;
}
// 首先验证是否是合并打开的文件 --robert 2012-10-17
System.out.println(list.get(0).getFullPath().toOSString());
if (isEditor) {
// 针对合并打开
if (list.get(0).getFullPath().toOSString().endsWith(".xlp")) {
List<String> multiFiles = new XLFHandler().getMultiFiles(list.get(0));
if (multiFiles.size() > 0) {
list = new ArrayList<IFile>();
}
for (String filePath : multiFiles) {
list.add(ResourceUtils.fileToIFile(filePath));
}
}
}
List<IFile> lstFiles = new ArrayList<IFile>();
XLFValidator.resetFlag();
for (IFile iFile : list) {
if (!XLFValidator.validateXliffFile(iFile)) {
lstFiles.add(iFile);
}
}
CommonFunction.removeRepeateSelect(list);
XLFValidator.resetFlag();
if (!(list instanceof ArrayList)) {
list = new ArrayList<IFile>(list);
}
list.removeAll(lstFiles);
if (list.size() == 0) {
return null;
}
ArrayList<ConverterViewModel> converterViewModels = new ArrayList<ConverterViewModel>();
for (int i = 0; i < list.size(); i++) {
Object adapter = Platform.getAdapterManager().getAdapter(list.get(i), IConversionItem.class);
IConversionItem sourceItem = null;
if (adapter instanceof IConversionItem) {
sourceItem = (IConversionItem) adapter;
}
ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_REVERSE);
// 记住所选择的文件
converterViewModel.setConversionItem(sourceItem);
converterViewModels.add(converterViewModel);
}
IProject project = list.get(0).getProject();
ReverseConversionWizard wizard = new ReverseConversionWizard(converterViewModels, project);
TSWizardDialog dialog = new TSWizardDialog(shell, wizard) {
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.FINISH_ID).setText(Messages.getString("handler.OpenConversionDialogHandler.finishLbl"));
}
};
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
final List<ConverterViewModel> models = wizard.getConverterViewModels();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(Messages.getString("handler.OpenReverseConversionDialogHandler.task1"));
monitor.beginTask(Messages.getString("handler.OpenReverseConversionDialogHandler.task2"), models.size());
for (ConverterViewModel converterViewModel : models) {
try {
IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
subMonitor.setTaskName(Messages.getString("handler.OpenReverseConversionDialogHandler.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
converterViewModel.convertWithoutJob(subMonitor);
} catch (ConverterException e) {
// Bug #2485:转换文件失败时,提示框显示有问题
throw new InvocationTargetException(e, e.getMessage());
}
}
monitor.done();
}
};
try {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} catch (InvocationTargetException e) {
MessageDialog.openInformation(shell, Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle2"), e.getMessage());
LOGGER.error("", e);
} catch (InterruptedException e) {
MessageDialog.openInformation(shell, Messages.getString("handler.OpenReverseConversionDialogHandler.msgTitle2"), e.getMessage());
LOGGER.error("", e);
}
}
return null;
}
use of net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard 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