Search in sources :

Example 1 with AbstractProjectSettingPage

use of net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage 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)

Example 2 with AbstractProjectSettingPage

use of net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage in project translationstudio8 by heartsome.

the class ProjectSettingHandler method runWizardPageExtension.

/**
	 * 加载扩展向导页 ;
	 */
private void runWizardPageExtension() {
    IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor("net.heartsome.cat.ts.ui.extensionpoint.projectsetting");
    try {
        // 修改术语库重复
        extensionPages.clear();
        for (IConfigurationElement e : config) {
            final Object o = e.createExecutableExtension("class");
            if (o instanceof AbstractProjectSettingPage) {
                ISafeRunnable runnable = new ISafeRunnable() {

                    public void handleException(Throwable exception) {
                        logger.error(Messages.getString("handlers.ProjectSettingHandler.logger1"), exception);
                    }

                    public void run() throws Exception {
                        extensionPages.add((AbstractProjectSettingPage) o);
                    }
                };
                SafeRunner.run(runnable);
            }
        }
    } catch (CoreException ex) {
        logger.error(Messages.getString("handlers.ProjectSettingHandler.logger1"), ex);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) AbstractProjectSettingPage(net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

AbstractProjectSettingPage (net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage)2 CoreException (org.eclipse.core.runtime.CoreException)2 ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)1 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)1 ProjectSettingBaseInfoPage (net.heartsome.cat.ts.ui.projectsetting.ProjectSettingBaseInfoPage)1 ProjectSettingDialog (net.heartsome.cat.ts.ui.projectsetting.ProjectSettingDialog)1 ProjectSettingLanguagePage (net.heartsome.cat.ts.ui.projectsetting.ProjectSettingLanguagePage)1 IProject (org.eclipse.core.resources.IProject)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 IPreferenceNode (org.eclipse.jface.preference.IPreferenceNode)1 PreferenceManager (org.eclipse.jface.preference.PreferenceManager)1 PreferenceNode (org.eclipse.jface.preference.PreferenceNode)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1