Search in sources :

Example 11 with TSWizardDialog

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

the class UpdateTMHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    ArrayList<IFile> lstXliff = new ArrayList<IFile>();
    //		boolean isShowCurrentLangBtn = true;
    if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
        // 导航视图处于激活状态
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
        StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        // ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
            List<?> lstObj = ((IStructuredSelection) selection).toList();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (file.getFileExtension() != null && CommonFunction.validXlfExtension(file.getFileExtension())) {
                        lstXliff.add(file);
                    }
                } else if (obj instanceof IFolder) {
                    try {
                        ResourceUtils.getXliffs((IFolder) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
                    }
                } else if (obj instanceof IProject) {
                    try {
                        ResourceUtils.getXliffs((IProject) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
                    }
                }
            }
            CommonFunction.removeRepeateSelect(lstXliff);
            if (lstXliff.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
                return null;
            }
            Iterator<IFile> iterator = lstXliff.iterator();
            while (iterator.hasNext()) {
                IFile file = iterator.next();
                FileEditorInput editorInput = new FileEditorInput(file);
                IEditorPart editorPart = page.findEditor(editorInput);
                if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
                    //						isShowCurrentLangBtn = false;
                    break;
                }
            }
        } else {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
            return null;
        }
    } else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
        // nattable 处于激活状态
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        if (xliffEditor.isMultiFile()) {
            List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
            if (lstFile.size() > 0) {
                for (String filePath : lstFile) {
                    lstXliff.add(ResourceUtils.fileToIFile(filePath));
                }
            }
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            lstXliff.add(iFile);
        }
    }
    if (lstXliff.size() > 0) {
        if (lstXliff.size() > 1) {
            String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
            for (int i = 1; i < lstXliff.size(); i++) {
                String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
                if (!projectPath.equals(projectPath2)) {
                    MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
                    return null;
                }
            }
        }
        ArrayList<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : lstXliff) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        lstXliff.removeAll(lstFiles);
        if (lstXliff.size() == 0) {
            return null;
        }
        ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
        if (projectConfig.getDefaultTMDb() == null) {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
            return null;
        }
        UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
        TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
        //			UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
        dialog.open();
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) UpdateTMWizard(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizard) Shell(org.eclipse.swt.widgets.Shell) UpdateTMWizardDialog(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizardDialog) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) IEditorInput(org.eclipse.ui.IEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with TSWizardDialog

use of net.heartsome.cat.common.ui.wizard.TSWizardDialog 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)

Example 13 with TSWizardDialog

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

the class NewProjectHandler method execute.

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

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            super.createButtonsForButtonBar(parent);
            getButton(IDialogConstants.FINISH_ID).setText(Messages.getString("handlers.NewProjectHandler.finishLbl"));
        }

        // robert help 2012-09-06
        @Override
        protected Control createHelpControl(Composite parent) {
            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) {
                    String language = CommonFunction.getSystemLanguage();
                    String helpUrl = "";
                    if (getCurrentPage() instanceof NewProjectWizardProjInfoPage) {
                        // ROBERTHELP 新建项目-项目信息
                        helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s02.html#create-project-wizard-project-info", language);
                        PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                    } else if (getCurrentPage() instanceof NewProjectWizardLanguagePage) {
                        // ROBERTHELP 新建项目-语言信息
                        helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s02.html#create-project-wizard-languages", language);
                        PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                    } else if (getCurrentPage() instanceof AbstractNewProjectWizardPage) {
                        if ("TM".equals(((AbstractNewProjectWizardPage) getCurrentPage()).getPageType())) {
                            // ROBERTHELP 新建项目-记忆库
                            helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s02.html#create-project-wizard-tm", language);
                            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                        } else {
                            // ROBERTHELP 新建项目-术语库
                            helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s02.html#create-project-wizard-tb", language);
                            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                        }
                    } else if (getCurrentPage() instanceof NewProjectWizardSourceFilePage) {
                        // ROBERTHELP 新建项目-源文件
                        helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s02.html#create-project-wizard-source-file", language);
                        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) NewProjectWizardSourceFilePage(net.heartsome.cat.ts.ui.wizards.NewProjectWizardSourceFilePage) NewProjectWizardProjInfoPage(net.heartsome.cat.ts.ui.wizards.NewProjectWizardProjInfoPage) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) AbstractNewProjectWizardPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractNewProjectWizardPage) NewProjectWizardDialog(net.heartsome.cat.ts.ui.wizards.NewProjectWizardDialog) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NewProjectWizardLanguagePage(net.heartsome.cat.ts.ui.wizards.NewProjectWizardLanguagePage) NewProjectWizard(net.heartsome.cat.ts.ui.wizards.NewProjectWizard) 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