Search in sources :

Example 1 with ProjectSettingBaseInfoPage

use of net.heartsome.cat.ts.ui.projectsetting.ProjectSettingBaseInfoPage 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

ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)1 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)1 AbstractProjectSettingPage (net.heartsome.cat.ts.ui.extensionpoint.AbstractProjectSettingPage)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 CoreException (org.eclipse.core.runtime.CoreException)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