Search in sources :

Example 31 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project translationstudio8 by heartsome.

the class CustomFilterDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    gray = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
    black = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
    tParent = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.swtDefaults().extendedMargins(5, 5, 10, 0).numColumns(2).equalWidth(false).applyTo(tParent);
    tParent.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite cmpLeft = new Composite(tParent, SWT.BORDER);
    cmpLeft.setLayout(new GridLayout(2, false));
    GridDataFactory.swtDefaults().applyTo(cmpLeft);
    Composite cmpList = new Composite(cmpLeft, SWT.NONE);
    cmpList.setLayout(new GridLayout(1, true));
    cmpList.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(cmpList, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.c1Lbl"));
    initCustomFilterList(cmpList);
    Composite cmpBtn = new Composite(cmpLeft, SWT.None);
    cmpBtn.setLayout(new GridLayout());
    cmpBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    Button addCustom = new Button(cmpBtn, SWT.PUSH);
    addCustom.setText(Messages.getString("dialog.CustomFilterDialog.addCustom"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addCustom);
    addCustom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (isChange()) {
                if (!MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg1"))) {
                    return;
                }
            }
            refresh();
        }
    });
    Button delCustom = new Button(cmpBtn, SWT.PUSH);
    delCustom.setText(Messages.getString("dialog.CustomFilterDialog.delCustom"));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(delCustom);
    delCustom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] filters = customFilterList.getSelection();
            if (filters != null && filters.length > 0) {
                if (MessageDialog.openConfirm(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg2"))) {
                    for (int i = 0; i < filters.length; i++) {
                        customFilters.remove(filters[i]);
                        customFiltersAddition.remove(filters[i]);
                        customFiltersIndex.remove(filters[i]);
                        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                        if (window != null) {
                            IWorkbenchPage page = window.getActivePage();
                            if (page != null) {
                                IEditorReference[] editors = page.getEditorReferences();
                                for (IEditorReference ef : editors) {
                                    IEditorPart editor = ef.getEditor(false);
                                    if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
                                        Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo();
                                        if (cb != null && !cb.isDisposed()) {
                                            cb.remove(filters[i]);
                                        }
                                    }
                                }
                            }
                        }
                        //							cmbFilter.remove(filters[i]);
                        customFilterList.remove(filters[i]);
                        XLFHandler.getFilterMap().remove(filters[i]);
                    }
                    PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, customFilters);
                    PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex);
                }
            } else {
                MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg3"));
            }
        }
    });
    Button editCustom = new Button(cmpBtn, SWT.PUSH);
    editCustom.setText(Messages.getString("dialog.CustomFilterDialog.editCustom"));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).applyTo(editCustom);
    editCustom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            edit();
        }
    });
    Composite cmpRight = new Composite(tParent, SWT.NONE);
    cmpRight.setLayout(new GridLayout(1, true));
    cmpRight.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite top = new Composite(cmpRight, SWT.NONE);
    top.setLayout(new GridLayout(2, false));
    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(top, SWT.NONE).setText(Messages.getString("dialog.CustomFilterDialog.topLbl"));
    filterNameTxt = new Text(top, SWT.BORDER);
    filterNameTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filterNameTxt.forceFocus();
    top = new Composite(cmpRight, SWT.NONE);
    top.setLayout(new GridLayout(2, false));
    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    andBtn = new Button(top, SWT.RADIO);
    andBtn.setText(Messages.getString("dialog.CustomFilterDialog.andBtn"));
    andBtn.setSelection(true);
    orBtn = new Button(top, SWT.RADIO);
    orBtn.setText(Messages.getString("dialog.CustomFilterDialog.orBtn"));
    scroll = new ScrolledComposite(cmpRight, SWT.V_SCROLL | SWT.BORDER);
    scroll.setAlwaysShowScrollBars(true);
    scroll.setLayoutData(new GridData(GridData.FILL_BOTH));
    scroll.setExpandHorizontal(true);
    scroll.setExpandVertical(true);
    //		scroll.setSize(500, 200);
    dynaComp = new Composite(scroll, SWT.None);
    scroll.setContent(dynaComp);
    dynaComp.setLayout(new GridLayout(1, true));
    new DynaComposite(dynaComp, SWT.NONE);
    return parent;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) IEditorPart(org.eclipse.ui.IEditorPart) GridLayout(org.eclipse.swt.layout.GridLayout) IEditorReference(org.eclipse.ui.IEditorReference) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 32 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project translationstudio8 by heartsome.

the class CustomFilterDialog method okPressed.

@Override
protected void okPressed() {
    String filterNameStr = filterNameTxt.getText();
    if (filterNameStr == null || "".equals(filterNameStr)) {
        MessageDialog.openInformation(getShell(), "", Messages.getString("dialog.CustomFilterDialog.msg6"));
        return;
    }
    StringBuilder xpath = new StringBuilder();
    String link = andBtn.getSelection() ? " and " : " or ";
    ArrayList<String[]> tempValue = new ArrayList<String[]>();
    for (DynaComposite comp : conditionList) {
        // 得到所有自定义条件组合的xpath
        String tempXpath = comp.getXpath(true);
        if (RESULT_FAILED.equals(tempXpath)) {
            return;
        }
        xpath.append(tempXpath).append(link);
        tempValue.add(comp.getTempIndex());
    }
    if (xpath.length() > 0) {
        if (isAdd()) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window != null) {
                IWorkbenchPage page = window.getActivePage();
                if (page != null) {
                    IEditorReference[] editors = page.getEditorReferences();
                    for (IEditorReference e : editors) {
                        IEditorPart editor = e.getEditor(false);
                        if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
                            Combo cb = ((XLIFFEditorImplWithNatTable) editor).getFilterCombo();
                            if (cb != null && !cb.isDisposed()) {
                                cb.add(filterNameTxt.getText());
                            }
                        }
                    }
                }
            }
        //				cmbFilter.add(filterNameTxt.getText());
        } else {
            XLFHandler.getFilterMap().put(filterNameTxt.getText(), xpath.substring(0, xpath.lastIndexOf(link)));
        }
        customFilters.put(filterNameStr, xpath.substring(0, xpath.lastIndexOf(link)));
        customFiltersAddition.put(filterNameStr, link.trim());
        customFiltersIndex.put(filterNameStr, tempValue);
        PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION, new TreeMap<String, String>(customFilters));
        PreferenceStore.saveMap(IPreferenceConstants.FILTER_CONDITION_ADDITION, customFiltersAddition);
        PreferenceStore.saveCustomCondition(IPreferenceConstants.FILTER_CONDITION_INDEX, customFiltersIndex);
        reload();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo) IEditorPart(org.eclipse.ui.IEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 33 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project translationstudio8 by heartsome.

the class ColorConfigLoader method loadColor.

private void loadColor() {
    Device device = Activator.getDefault().getWorkbench().getDisplay();
    if (pfStore == null) {
        pfStore = Activator.getDefault().getPreferenceStore();
        pfStore.addPropertyChangeListener(this);
    }
    colorConfigBean.release();
    colorConfigBean.setPtColor(getColor(device, IColorPreferenceConstant.PT_COLOR));
    colorConfigBean.setQtColor(getColor(device, IColorPreferenceConstant.QT_COLOR));
    colorConfigBean.setMtColor(getColor(device, IColorPreferenceConstant.MT_COLOR));
    colorConfigBean.setTm101Color(getColor(device, IColorPreferenceConstant.TM_MATCH101_COLOR));
    colorConfigBean.setTm100Color(getColor(device, IColorPreferenceConstant.TM_MATCH100_COLOR));
    colorConfigBean.setTm90Color(getColor(device, IColorPreferenceConstant.TM_MATCH90_COLOR));
    colorConfigBean.setTm80Color(getColor(device, IColorPreferenceConstant.TM_MATCH80_COLOR));
    colorConfigBean.setTm70Color(getColor(device, IColorPreferenceConstant.TM_MATCH70_COLOR));
    colorConfigBean.setTm0Color(getColor(device, IColorPreferenceConstant.TM_MATCH0_COLOR));
    colorConfigBean.setSrcDiffFgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_FG_COLOR));
    colorConfigBean.setSrcDiffBgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_BG_COLOR));
    colorConfigBean.setTagFgColor(getColor(device, IColorPreferenceConstant.TAG_FG_COLOR));
    colorConfigBean.setTagBgColor(getColor(device, IColorPreferenceConstant.TAG_BG_COLOR));
    colorConfigBean.setWrongTagColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
    colorConfigBean.setErrorWordColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
    String strColor = colorConfigBean.toString();
    IXliffEditor xliffEditor = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IEditorPart editor = page.getActiveEditor();
            if (editor != null && editor instanceof IXliffEditor) {
                xliffEditor = (IXliffEditor) editor;
            }
        }
    }
    if (strCurColor != null && !strCurColor.equals(strColor)) {
        // 更改颜色设置后刷新界面
        if (xliffEditor != null) {
            xliffEditor.autoResize();
            xliffEditor.refresh();
        }
        if (window != null) {
            IWorkbenchPage page = window.getActivePage();
            if (page != null) {
                IViewPart viewPart = page.findView("net.heartsome.cat.ts.ui.translation.view.matchview");
                if (viewPart != null) {
                    IMatchViewPart part = (IMatchViewPart) viewPart;
                    part.refreshTable();
                }
            }
        }
        strCurColor = strColor;
    }
    Color highlightedTermColor = colorConfigBean.getHighlightedTermColor();
    RGB newRgb = StringConverter.asRGB(pfStore.getString(IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR));
    if (highlightedTermColor == null || highlightedTermColor.isDisposed()) {
        highlightedTermColor = new Color(device, newRgb);
    } else if (!highlightedTermColor.getRGB().equals(newRgb)) {
        highlightedTermColor.dispose();
        highlightedTermColor = new Color(device, newRgb);
        // had changed
        if (xliffEditor != null) {
            // 刷新
            xliffEditor.highlightedTerms(0, null);
        }
    }
    colorConfigBean.setHighlightedTermColor(highlightedTermColor);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) RGB(org.eclipse.swt.graphics.RGB) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 34 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project translationstudio8 by heartsome.

the class OpenMultiXliffHandler method execute.

@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
    if (currentSelection.isEmpty() || !(currentSelection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
    Iterator<Object> selectIt = structuredSelection.iterator();
    final ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    shell = window.getShell();
    // 先验证是否跨项目
    IProject selectedProject = null;
    while (selectIt.hasNext()) {
        Object object = selectIt.next();
        if (object instanceof IFile) {
            IFile iFile = (IFile) object;
            if (!CommonFunction.validXlfExtension(iFile.getFileExtension())) {
                MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), MessageFormat.format(Messages.getString("handlers.OpenMultiXliffHandler.msg1"), iFile.getFullPath().toOSString()));
                continue;
            }
            selectIFiles.add(iFile);
            if (selectedProject == null) {
                selectedProject = iFile.getProject();
            } else {
                if (selectedProject != iFile.getProject()) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg2"));
                    return null;
                }
            }
        } else if (object instanceof IContainer) {
            IContainer selectContainer = (IContainer) object;
            if (selectedProject == null) {
                selectedProject = selectContainer.getProject();
            }
            // 判断当前文件夹是否处于 XLIFF 文件夹下
            try {
                ResourceUtils.getXliffs(selectContainer, selectIFiles);
            } catch (CoreException e) {
                logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger1"), selectContainer.getFullPath().toOSString(), e);
            }
        }
    }
    // 过滤重复选择文件
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() < 2) {
        MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg3"));
        return null;
    }
    MultiFilesOper oper = new MultiFilesOper(selectedProject, selectIFiles);
    // 先验证这些文件是否已经合并打开,如果是,则退出
    if (oper.validExist()) {
        return null;
    }
    // 判断是否有重复打开的文件,并删除缓存中要合并打开的文件。
    if (oper.hasOpenedIFile()) {
        if (oper.getSelectIFiles().size() <= 0) {
            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg4"));
            return null;
        } else {
            boolean isResponse = MessageDialog.openConfirm(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle2"), Messages.getString("handlers.OpenMultiXliffHandler.msg5"));
            if (isResponse) {
                if (oper.getSelectIFiles().size() < 2) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg6"));
                    return null;
                }
            } else {
                return null;
            }
        }
    }
    final IFile multiIFile = oper.createMultiTempFile();
    if (multiIFile != null && multiIFile.exists()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.getString("handler.OpenMultiXliffHandler.tip1"), 10);
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 7, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                // 进行判断所选择文件的语言对是否符合标准,先解析文件
                final XLFHandler xlfHander = new XLFHandler();
                final Map<String, Object> newResultMap = xlfHander.openFiles(ResourceUtils.iFilesToFiles(selectIFiles), subMonitor);
                // 针对解析失败
                if (newResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) newResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), (String) newResultMap.get(Constant.RETURNVALUE_MSG));
                        }
                    });
                    return;
                }
                // 验证是否有多个语言
                boolean hasDiffrentLangPair = false;
                Map<String, ArrayList<String>> langMap = xlfHander.getLanguages();
                if (langMap.size() > 1) {
                    hasDiffrentLangPair = true;
                } else {
                    for (Entry<String, ArrayList<String>> entry : langMap.entrySet()) {
                        if (entry.getValue().size() > 1) {
                            hasDiffrentLangPair = true;
                        }
                    }
                }
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                if (hasDiffrentLangPair) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg7"));
                        }
                    });
                    // 先删除临时文件,再退出
                    try {
                        multiIFile.delete(true, monitor);
                    } catch (CoreException e) {
                        logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
                    }
                    return;
                }
                final boolean[] validateResult = new boolean[] { false };
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        validateResult[0] = XLFValidator.validateXlifIFiles(selectIFiles);
                    }
                });
                if (!validateResult[0]) {
                    try {
                        multiIFile.delete(true, monitor);
                    } catch (CoreException e) {
                        logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger2"), e);
                    }
                    return;
                }
                final FileEditorInput input = new FileEditorInput(multiIFile);
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        try {
                            // UNDO 这里合并打开时,要考虑传入参数xlfHandler,以防多次解析文件带来的消耗。
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, XLIFF_EDITOR_ID, true);
                        } catch (PartInitException e) {
                            e.printStackTrace();
                        }
                    }
                });
                if (monitor.isCanceled()) {
                    return;
                }
                monitor.worked(1);
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (Exception e) {
            logger.error(Messages.getString("handlers.OpenMultiXliffHandler.logger3"), e);
        }
    } else {
        MessageDialog.openInformation(shell, Messages.getString("handlers.OpenMultiXliffHandler.msgTitle"), Messages.getString("handlers.OpenMultiXliffHandler.msg8"));
        return null;
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IContainer(org.eclipse.core.resources.IContainer) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 35 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project translationstudio8 by heartsome.

the class ProjectSettingHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    runWizardPageExtension();
    ISelection curSelection = HandlerUtil.getCurrentSelection(event);
    if (curSelection != null && !curSelection.isEmpty() && curSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) curSelection;
        Object obj = selection.getFirstElement();
        if (obj instanceof IProject) {
            IProject project = (IProject) obj;
            ProjectConfiger cfg = ProjectConfigerFactory.getProjectConfiger(project);
            final ProjectInfoBean cfgBean = cfg.getCurrentProjectConfig();
            cfgBean.setProjectName(project.getName());
            ProjectSettingBaseInfoPage infoPage = new ProjectSettingBaseInfoPage(cfgBean);
            ProjectSettingLanguagePage langPag = new ProjectSettingLanguagePage(cfgBean);
            final PreferenceManager mgr = new PreferenceManager();
            IPreferenceNode infoNode = new PreferenceNode("infoPage", infoPage);
            IPreferenceNode langNode = new PreferenceNode("langPag", langPag);
            mgr.addToRoot(infoNode);
            mgr.addTo("infoPage", langNode);
            AbstractProjectSettingPage pageTm = getPageByType("TM");
            if (pageTm != null) {
                pageTm.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tmInfo", pageTm);
                mgr.addTo("infoPage", extensionNode);
            }
            AbstractProjectSettingPage pageTb = getPageByType("TB");
            if (pageTb != null) {
                pageTb.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tbInfo", pageTb);
                mgr.addTo("infoPage", extensionNode);
            }
            for (AbstractProjectSettingPage page : extensionPages) {
                page.setProjectInfoBean(cfgBean);
                IPreferenceNode extensionNode = new PreferenceNode("tbInfo", page);
                mgr.addTo("infoPage", extensionNode);
            }
            ProjectSettingDialog dialog = new ProjectSettingDialog(window.getShell(), mgr);
            dialog.create();
            dialog.setMessage(infoPage.getTitle());
            if (dialog.open() == 0) {
                cfg.updateProjectConfig(cfgBean);
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    logger.error("", e);
                }
            }
        } else {
            MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
            return null;
        }
    } else {
        MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
        return null;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ProjectSettingBaseInfoPage(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingBaseInfoPage) ProjectSettingDialog(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingDialog) ProjectSettingLanguagePage(net.heartsome.cat.ts.ui.projectsetting.ProjectSettingLanguagePage) PreferenceNode(org.eclipse.jface.preference.PreferenceNode) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractProjectSettingPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IProject(org.eclipse.core.resources.IProject) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ISelection(org.eclipse.jface.viewers.ISelection)

Aggregations

IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)363 IEditorPart (org.eclipse.ui.IEditorPart)136 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)102 PartInitException (org.eclipse.ui.PartInitException)81 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)41 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)39 IViewPart (org.eclipse.ui.IViewPart)39 ArrayList (java.util.ArrayList)37 IEditorReference (org.eclipse.ui.IEditorReference)35 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)32 IWorkbench (org.eclipse.ui.IWorkbench)32 IFile (org.eclipse.core.resources.IFile)30 ISelection (org.eclipse.jface.viewers.ISelection)29 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)27 Shell (org.eclipse.swt.widgets.Shell)26 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)24 CoreException (org.eclipse.core.runtime.CoreException)23 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)21 IProject (org.eclipse.core.resources.IProject)20 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)19