Search in sources :

Example 1 with TSWizardDialog

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

the class CheckUpdateHandler method doExecute.

@Override
protected void doExecute(LoadMetadataRepositoryJob job) {
    // TODO Auto-generated method stub		
    if (hasNoRepos) {
        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_CHECK);
        return;
    }
    if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
        UpdateWizard wizard = new UpdateWizard(getProvisioningUI(), operation, operation.getSelectedUpdates());
        TSWizardDialog dialog = new TSWizardDialog(getShell(), wizard);
        dialog.create();
        dialog.open();
    }
}
Also used : UpdateWizard(net.heartsome.cat.p2update.ui.UpdateWizard) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 2 with TSWizardDialog

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

the class AutomaticUpdate method doUpdate.

private void doUpdate() {
    if (operation == null) {
        return;
    }
    IStatus status = operation.getResolutionResult();
    // user cancelled
    if (status.getSeverity() == IStatus.CANCEL)
        return;
    // Special case those statuses where we would never want to open a wizard
    if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
        return;
    }
    if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
        UpdateWizard wizard = new UpdateWizard(getProvisioningUI(), operation, operation.getSelectedUpdates());
        TSWizardDialog dialog = new TSWizardDialog(getShell(), wizard);
        dialog.create();
        dialog.open();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) UpdateWizard(net.heartsome.cat.p2update.ui.UpdateWizard) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 3 with TSWizardDialog

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

the class ImportProjectHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    ImportProjectWizard wizard = new ImportProjectWizard();
    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}/ch07s03.html#import-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);
    dialog.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ImportProjectWizard(net.heartsome.cat.ts.importproject.wizards.ImportProjectWizard) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) 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)

Example 4 with TSWizardDialog

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

the class SplitXliffHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final String navegatorID = "net.heartsome.cat.common.ui.navigator.view";
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final Shell shell = window.getShell();
    IFile selectFile = null;
    XLIFFEditorImplWithNatTable xliffEditor = null;
    List<Integer> splitXlfPointsIndex = new LinkedList<Integer>();
    List<String> splitXlfPointsRowId = new LinkedList<String>();
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    // 如果是导航视图,那么就获取导航视图中选中的文件
    if (activePart instanceof IViewPart) {
        if (navegatorID.equals(activePart.getSite().getId())) {
            IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(navegatorID);
            ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
            if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
                Object object = structuredSelection.getFirstElement();
                if (object instanceof IFile) {
                    selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就退出操作
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                        return null;
                    }
                    FileEditorInput fileInput = new FileEditorInput(selectFile);
                    IEditorReference[] editorRefer = window.getActivePage().findEditors(fileInput, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                    IEditorPart editorPart = null;
                    if (editorRefer.length >= 1) {
                        editorPart = editorRefer[0].getEditor(true);
                        xliffEditor = (XLIFFEditorImplWithNatTable) editorPart;
                        if (window.getActivePage().getActiveEditor() != editorPart) {
                            window.getActivePage().activate(editorPart);
                        }
                    } else {
                        try {
                            xliffEditor = (XLIFFEditorImplWithNatTable) window.getActivePage().openEditor(fileInput, XLIFF_EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                        } catch (PartInitException e) {
                            LOGGER.error("", e);
                            e.printStackTrace();
                        }
                    }
                } else {
                    MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg1"));
                    return null;
                }
            }
        }
    } else if (activePart instanceof IEditorPart) {
        if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) {
            xliffEditor = (XLIFFEditorImplWithNatTable) activePart;
            selectFile = ((FileEditorInput) xliffEditor.getEditorInput()).getFile();
        }
    }
    // 根据每个tu节点的rowId获取其具体的位置,才好进行排序
    Map<Integer, String> pointIndexRowIdMap = new HashMap<Integer, String>();
    for (String rowId : xliffEditor.getSplitXliffPoints()) {
        // 获取指定tu节点所处其他结点的序列号
        int tuPostion = xliffEditor.getXLFHandler().getTUPositionByRowId(rowId);
        if (tuPostion >= 1) {
            splitXlfPointsIndex.add(tuPostion);
            pointIndexRowIdMap.put(tuPostion, rowId);
        }
    }
    if (splitXlfPointsIndex.size() <= 0) {
        MessageDialog.openInformation(shell, Messages.getString("handler.SplitXliffHandler.msgTitle"), Messages.getString("handler.SplitXliffHandler.msg2"));
        return null;
    }
    // 对切割点集合进行排序
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        int point1 = splitXlfPointsIndex.get(i);
        for (int j = i + 1; j < splitXlfPointsIndex.size(); j++) {
            int point2 = splitXlfPointsIndex.get(j);
            if (point1 > point2) {
                splitXlfPointsIndex.set(i, point2);
                splitXlfPointsIndex.set(j, point1);
                point1 = point2;
            }
        }
    }
    // 向存储rowId的list存放数据,这样的话,所存储的rowId就是经过排序了的。
    for (int i = 0; i < splitXlfPointsIndex.size(); i++) {
        splitXlfPointsRowId.add(pointIndexRowIdMap.get(splitXlfPointsIndex.get(i)));
    }
    SplitOrMergeXlfModel model = new SplitOrMergeXlfModel();
    model.setSplitFile(selectFile);
    model.setSplitXlfPointsIndex(splitXlfPointsIndex);
    model.setSplitXlfPointsRowId(splitXlfPointsRowId);
    model.setXliffEditor(xliffEditor);
    model.setShell(shell);
    SplitXliffWizard wizard = new SplitXliffWizard(model);
    final TSWizardDialog dialog = new NattableWizardDialog(shell, wizard);
    dialog.open();
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) SplitOrMergeXlfModel(net.heartsome.cat.ts.handlexlf.split.SplitOrMergeXlfModel) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SplitXliffWizard(net.heartsome.cat.ts.handlexlf.wizard.SplitXliffWizard) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NattableWizardDialog(net.heartsome.cat.ts.handlexlf.wizard.NattableWizardDialog) IEditorPart(org.eclipse.ui.IEditorPart) LinkedList(java.util.LinkedList) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog)

Example 5 with TSWizardDialog

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

the class OpenConversionDialogHandler method execute.

@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
    CommonFunction.removeRepeateSelect(list);
    if (list == null || list.size() == 0) {
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.OpenConversionDialogHandler.msgTitle1"), Messages.getString("handler.OpenConversionDialogHandler.msg1"));
        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_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) {

        @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();
        final List<IFile> targetFiles = new ArrayList<IFile>();
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.setTaskName(Messages.getString("handler.OpenConversionDialogHandler.task1"));
                monitor.beginTask(Messages.getString("handler.OpenConversionDialogHandler.task2"), models.size());
                for (ConverterViewModel converterViewModel : models) {
                    try {
                        IProgressMonitor subMonitor = Progress.getSubMonitor(monitor, 1);
                        subMonitor.setTaskName(Messages.getString("handler.OpenConversionDialogHandler.task3") + converterViewModel.getConversionItem().getLocation().toOSString());
                        converterViewModel.convertWithoutJob(subMonitor);
                        List<File> tgtFileList = converterViewModel.getGenerateTgtFileList();
                        for (File f : tgtFileList) {
                            IFile tgtIfile = ConverterUtil.localPath2IFile(f.getAbsolutePath());
                            if (tgtIfile != null) {
                                targetFiles.add(tgtIfile);
                            }
                        }
                        // 若新转换的 xliff 文件重复,那么关闭已经打开的重复文件,防止文件同步冲突	robert	2013-04-01
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CommonFunction.closePointEditor(targetFiles);
                            }
                        });
                    } catch (ConverterException e) {
                        final String message = e.getMessage();
                        LOGGER.error("", e);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(shell, Messages.getString("handler.OpenConversionDialogHandler.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("handler.OpenConversionDialogHandler.msgTitle2"), message);
                            }
                        });
                    }
                }
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (InvocationTargetException e) {
            MessageDialog.openError(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), e.getMessage());
            LOGGER.error("", e);
        } catch (InterruptedException e) {
            MessageDialog.openError(shell, Messages.getString("handler.OpenConversionDialogHandler.msgTitle2"), e.getMessage());
            LOGGER.error(e.getMessage());
        }
        if (wizard.isOpenPreTranslation()) {
            // 加载转换器扩展
            final IExecutePretranslation[] impls = new IExecutePretranslation[1];
            IConfigurationElement[] config2 = Platform.getExtensionRegistry().getConfigurationElementsFor("net.heartsome.converter.extension.pretranslation");
            try {
                for (IConfigurationElement e : config2) {
                    final Object o = e.createExecutableExtension("class");
                    if (o instanceof IExecutePretranslation) {
                        ISafeRunnable runnable1 = new ISafeRunnable() {

                            public void handleException(Throwable exception) {
                                LOGGER.error(Messages.getString("handler.OpenConversionDialogHandler.logger1"), exception);
                            }

                            public void run() throws Exception {
                                impls[0] = (IExecutePretranslation) o;
                            }
                        };
                        SafeRunner.run(runnable1);
                    }
                }
            } catch (CoreException ex) {
                LOGGER.error(Messages.getString("handler.OpenConversionDialogHandler.logger1"), ex);
            }
            if (impls[0] != null) {
                if (targetFiles.size() < 1) {
                    return null;
                }
                impls[0].executePreTranslation(targetFiles);
            }
        }
    }
    return null;
}
Also used : ConverterException(net.heartsome.cat.converter.ConverterException) IFile(org.eclipse.core.resources.IFile) ConversionWizard(net.heartsome.cat.convert.ui.wizard.ConversionWizard) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IExecutePretranslation(net.heartsome.cat.convert.extenstion.IExecutePretranslation) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) Composite(org.eclipse.swt.widgets.Composite) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ConverterException(net.heartsome.cat.converter.ConverterException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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