Search in sources :

Example 6 with TSWizardDialog

use of net.heartsome.cat.common.ui.wizard.TSWizardDialog 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;
}
Also used : ConverterException(net.heartsome.cat.converter.ConverterException) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ReverseConversionWizard(net.heartsome.cat.convert.ui.wizard.ReverseConversionWizard) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 7 with TSWizardDialog

use of net.heartsome.cat.common.ui.wizard.TSWizardDialog in project translationstudio8 by heartsome.

the class IConverterCallerImpl method openConverter.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.ts.ui.extensionpoint.IConverterCaller#openConverter(java.util.List)
	 */
public void openConverter(List<IFile> files) {
    if (files == null || files.size() == 0) {
        return;
    }
    final Shell shell = Display.getCurrent().getActiveShell();
    ArrayList<IFile> list = new ArrayList<IFile>();
    ArrayList<IFile> wrongFiles = new ArrayList<IFile>();
    for (IFile file : files) {
        String fileExtension = file.getFileExtension();
        if (getLegalFileExtensions() == null || getLegalFileExtensions().length == 0) {
            // 未限制后缀名的情况
            list.add(file);
        } else {
            // 限制了后缀名的情况
            if (fileExtension == null) {
                // 无后缀名的文件
                fileExtension = "";
            }
            if (CommonFunction.containsIgnoreCase(getLegalFileExtensions(), fileExtension)) {
                list.add(file);
            } else {
                wrongFiles.add(file);
            }
        }
    }
    if (!wrongFiles.isEmpty()) {
        StringBuffer msg = new StringBuffer(Messages.getString("extension.IConverterCallerImpl.msg1"));
        for (IFile iFile : wrongFiles) {
            msg.append("\n").append(iFile.getFullPath().toOSString());
        }
        if (!MessageDialog.openConfirm(shell, Messages.getString("extension.IConverterCallerImpl.msgTitle1"), msg.toString())) {
            return;
        }
    }
    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_POSITIVE);
        // 记住所选择的文件
        converterViewModel.setConversionItem(sourceItem);
        converterViewModels.add(converterViewModel);
    }
    IProject project = list.get(0).getProject();
    ConversionWizard wizard = new ConversionWizard(converterViewModels, project);
    TSWizardDialog dialog = new TSWizardDialog(shell, wizard);
    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("extension.IConverterCallerImpl.task1"));
                monitor.beginTask(Messages.getString("extension.IConverterCallerImpl.task2"), models.size());
                for (ConverterViewModel converterViewModel : models) {
                    try {
                        IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
                        subMonitor.setTaskName(Messages.getString("extension.IConverterCallerImpl.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
                        converterViewModel.convertWithoutJob(subMonitor);
                    } catch (ConverterException e) {
                        final String message = e.getMessage();
                        LOGGER.error("", e);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(shell, Messages.getString("extension.IConverterCallerImpl.msgTitle2"), message);
                            }
                        });
                    } catch (Exception e) {
                        final String message = e.getMessage();
                        LOGGER.error("", e);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(shell, Messages.getString("extension.IConverterCallerImpl.msgTitle2"), message);
                            }
                        });
                    }
                }
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (InvocationTargetException e) {
            MessageDialog.openInformation(shell, Messages.getString("extension.IConverterCallerImpl.msgTitle2"), e.getMessage());
            LOGGER.error("", e);
        } catch (InterruptedException e) {
            MessageDialog.openInformation(shell, Messages.getString("extension.IConverterCallerImpl.msgTitle2"), e.getMessage());
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : ConverterException(net.heartsome.cat.converter.ConverterException) IFile(org.eclipse.core.resources.IFile) ConversionWizard(net.heartsome.cat.convert.ui.wizard.ConversionWizard) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) ConverterException(net.heartsome.cat.converter.ConverterException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 8 with TSWizardDialog

use of net.heartsome.cat.common.ui.wizard.TSWizardDialog in project translationstudio8 by heartsome.

the class ExportHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection currentSelection = getSelectionToUse(event);
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IExportWizard wizard = getExportWizard(event);
    wizard.init(window.getWorkbench(), currentSelection);
    TSWizardDialog dialog = new TSWizardDialog(window.getShell(), wizard);
    dialog.create();
    dialog.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IExportWizard(org.eclipse.ui.IExportWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 9 with TSWizardDialog

use of net.heartsome.cat.common.ui.wizard.TSWizardDialog in project translationstudio8 by heartsome.

the class MergeXliffHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
        if (structuredSelection.size() < 2) {
            MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"), Messages.getString("handler.MergeXliffHandler.msg1"));
            return null;
        }
        Vector<IFile> seleFiles = new Vector<IFile>();
        String notXlfFile = "";
        @SuppressWarnings("rawtypes") Iterator selectIt = structuredSelection.iterator();
        while (selectIt.hasNext()) {
            Object object = selectIt.next();
            if (object instanceof IFile) {
                IFile selectFile = (IFile) object;
                String fileExtension = selectFile.getFileExtension();
                // 如果后缀名不是xlf,那么就进行提示
                if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                    notXlfFile += selectFile.getFullPath().toOSString() + ",";
                }
                seleFiles.add(selectFile);
            }
        }
        if (notXlfFile.length() > 0) {
            notXlfFile = notXlfFile.substring(0, notXlfFile.length() - 1);
            boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("handler.MergeXliffHandler.msgTitle2"), MessageFormat.format(Messages.getString("handler.MergeXliffHandler.msg2"), new Object[] { notXlfFile }));
            if (!isSure) {
                return null;
            }
        }
        List<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : seleFiles) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        seleFiles.removeAll(lstFiles);
        if (seleFiles.size() == 0) {
            return null;
        }
        if (seleFiles.size() > 0) {
            String projectPath = seleFiles.get(0).getProject().getFullPath().toOSString();
            for (int i = 1; i < seleFiles.size(); i++) {
                if (!projectPath.equals(seleFiles.get(i).getProject().getFullPath().toOSString())) {
                    MessageDialog.openInformation(shell, Messages.getString("handler.MergeXliffHandler.msgTitle1"), Messages.getString("handler.MergeXliffHandler.msg3"));
                    return null;
                }
            }
            SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
            model.setMergeXliffFile(seleFiles);
            MergeXliffWizard wizard = new MergeXliffWizard(model);
            TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
            dialog.open();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) SplitOrMergeXlfModel(net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel) NattableWizardDialog(net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) Vector(java.util.Vector) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) MergeXliffWizard(net.heartsome.cat.ts.handlexlf.wizard.MergeXliffWizard)

Example 10 with TSWizardDialog

use of net.heartsome.cat.common.ui.wizard.TSWizardDialog in project translationstudio8 by heartsome.

the class ExportProjectHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    ExportProjectWizard wizard = new ExportProjectWizard();
    TSWizardDialog dialog = new TSWizardDialog(window.getShell(), wizard) {

        /**
			 * 添加帮助按钮 robert 2012-09-06
			 */
        @Override
        protected Control createHelpControl(Composite parent) {
            // ROBERTHELP 导出项目
            String language = CommonFunction.getSystemLanguage();
            final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch07s02.html#export-project", language);
            Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
            ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
            ((GridLayout) parent.getLayout()).numColumns++;
            toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
            final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
            toolBar.setCursor(cursor);
            toolBar.addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    cursor.dispose();
                }
            });
            ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
            helpItem.setImage(helpImage);
            //$NON-NLS-1$
            helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
            helpItem.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                }
            });
            return toolBar;
        }
    };
    dialog.setHelpAvailable(true);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    if (null != root) {
        try {
            root.refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException e) {
            LOGGER.error("", e);
        }
    }
    dialog.open();
    return null;
}
Also used : ExportProjectWizard(net.heartsome.cat.ts.exportproject.wizards.ExportProjectWizard) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

TSWizardDialog (net.heartsome.cat.common.ui.wizard.TSWizardDialog)13 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)7 IFile (org.eclipse.core.resources.IFile)6 ArrayList (java.util.ArrayList)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Composite (org.eclipse.swt.widgets.Composite)5 ConverterViewModel (net.heartsome.cat.convert.ui.model.ConverterViewModel)4 IConversionItem (net.heartsome.cat.convert.ui.model.IConversionItem)4 IProject (org.eclipse.core.resources.IProject)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ConversionWizard (net.heartsome.cat.convert.ui.wizard.ConversionWizard)3 ConverterException (net.heartsome.cat.converter.ConverterException)3 CoreException (org.eclipse.core.runtime.CoreException)3 ISelection (org.eclipse.jface.viewers.ISelection)3 DisposeEvent (org.eclipse.swt.events.DisposeEvent)3 DisposeListener (org.eclipse.swt.events.DisposeListener)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Cursor (org.eclipse.swt.graphics.Cursor)3 Image (org.eclipse.swt.graphics.Image)3