Search in sources :

Example 1 with IViewPart

use of org.eclipse.ui.IViewPart in project gfm_viewer by satyagraha.

the class ViewManager method activateView.

/**
     * Activate a view by id.
     * 
     * @param event
     * @param viewId
     * @throws ExecutionException
     */
public static void activateView(ExecutionEvent event, String viewId) throws ExecutionException {
    try {
        IViewPart view = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
        HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().activate(view);
    } catch (PartInitException e) {
        throw new ExecutionException("failed to show view", e);
    }
}
Also used : IViewPart(org.eclipse.ui.IViewPart) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with IViewPart

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

the class OpenViewHandler 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 viewId = event.getParameter("ViewId");
    if (viewId == null) {
        return null;
    }
    IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart view = workbenchPage.findView(viewId);
    if (view == null) {
        try {
            workbenchPage.showView(viewId);
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    } else {
        workbenchPage.hideView(view);
    }
    //		commandService.refreshElements(event.getCommand().getId(), null);
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with IViewPart

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

the class ApplicationWorkbenchWindowAdvisor method setInitLinkEnable.

/**
	 * 当程序第一次运行时(或是重新换了命名空间),设置项目视图的 link with editor 按钮处于选中状态
	 * robert	2013-01-04
	 */
private void setInitLinkEnable() {
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    boolean isInitialRun = !store.getBoolean(IPreferenceConstants.INITIAL_RUN);
    if (isInitialRun) {
        IViewPart navigator = getWindowConfigurer().getWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
        CommonNavigator commonNavigator = (CommonNavigator) navigator;
        commonNavigator.setLinkingEnabled(true);
        store.setValue(IPreferenceConstants.INITIAL_RUN, true);
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with IViewPart

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

the class ApplicationWorkbenchWindowAdvisor method addWorkplaceListener.

public void addWorkplaceListener() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.addResourceChangeListener(new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {
            //刷新项目导航视图
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    IViewPart findView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
                    if (null == findView) {
                        return;
                    }
                    IAction refreshActionHandler = findView.getViewSite().getActionBars().getGlobalActionHandler(ActionFactory.REFRESH.getId());
                    if (null == refreshActionHandler) {
                        return;
                    }
                    refreshActionHandler.run();
                }
            });
        }
    });
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IViewPart(org.eclipse.ui.IViewPart) IAction(org.eclipse.jface.action.IAction) IWorkspace(org.eclipse.core.resources.IWorkspace) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener)

Example 5 with IViewPart

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

the class ExecuteBingTransHandler method execute.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof IXliffEditor)) {
        return null;
    }
    // check the google translation state: check the key availability
    PrefrenceParameters ps = PrefrenceParameters.getInstance();
    if (!ps.getState()) {
        MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg"));
        return null;
    }
    String tshelp = System.getProperties().getProperty("TSHelp");
    String tsstate = System.getProperties().getProperty("TSState");
    if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
        LoggerFactory.getLogger(ExecuteBingTransHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
        System.exit(0);
    }
    final IXliffEditor xliffEditor = (IXliffEditor) editor;
    final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
    if (selectedRowIndexs.length == 0) {
        return null;
    }
    //		int currentRowIndex = selectedRowIndexs[0];
    //		TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(currentRowIndex);
    //		if (transUnitBean == null) {
    //			return null;
    //		}
    //		String srcPureText = transUnitBean.getSrcText();
    //		String tgtLanguage = xliffEditor.getTgtColumnName();
    //		String srcLanguage = xliffEditor.getSrcColumnName();
    //		TransUnitInfo2TranslationBean tuInfo2Trans = new TransUnitInfo2TranslationBean();
    //		tuInfo2Trans.setSrcPureText(srcPureText);
    //		tuInfo2Trans.setSrcLanguage(srcLanguage);
    //		tuInfo2Trans.setTgtLangugage(tgtLanguage);
    ISimpleMatcher matcher = new SimpleMatcherBingImpl();
    //		String tgtText = matcher.executeMatch(tuInfo2Trans);
    //		if (tgtText.equals("")) {
    //			return null;
    //		}
    //		AltTransBean bean = new AltTransBean(srcPureText, tgtText, srcLanguage, tgtLanguage,
    //				matcher.getMathcerOrigin(), matcher.getMathcerToolId());
    //		bean.getMatchProps().put("match-quality", "100");
    //		bean.getMatchProps().put("hs:matchType", matcher.getMatcherType());
    //		bean.setSrcContent(srcPureText);
    //		bean.setTgtContent(tgtText);
    //		List<AltTransBean> newAltTrans = new ArrayList<AltTransBean>();
    //		newAltTrans.add(bean);
    // check if need save the AltTrans to file
    //		if (CommonFunction.checkEdition("U") && matcher.isSuportPreTrans()) {
    //			List<String> oldToolIds = new ArrayList<String>();
    //			oldToolIds.add(matcher.getMathcerToolId());
    //			xliffEditor.getXLFHandler().updateAltTrans(xliffEditor.getXLFHandler().getRowId(currentRowIndex), newAltTrans, oldToolIds);
    //		}
    IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
    if (viewPart != null && viewPart instanceof MatchViewPart) {
        MatchViewPart matchView = (MatchViewPart) viewPart;
        //matchView.refreshView(xliffEditor, selectedRowIndexs[0]);
        //			matchView.refreshViewByToolId(xliffEditor, newAltTrans, matcher.getMathcerToolId());
        //			matchView.replaceMatchs(newAltTrans);
        //			newAltTrans.clear();
        matchView.manualExecSimpleTranslation(matcher);
    }
    return null;
}
Also used : MatchViewPart(net.heartsome.cat.ts.ui.translation.view.MatchViewPart) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SimpleMatcherBingImpl(net.heartsome.cat.ts.bingtrans.SimpleMatcherBingImpl) IViewPart(org.eclipse.ui.IViewPart) ISimpleMatcher(net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher) PrefrenceParameters(net.heartsome.cat.ts.bingtrans.bean.PrefrenceParameters) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Aggregations

IViewPart (org.eclipse.ui.IViewPart)95 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)52 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)38 IEditorPart (org.eclipse.ui.IEditorPart)31 PartInitException (org.eclipse.ui.PartInitException)25 IViewReference (org.eclipse.ui.IViewReference)23 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)14 IEditorInput (org.eclipse.ui.IEditorInput)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 ITermViewPart (net.heartsome.cat.ts.ui.view.ITermViewPart)10 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)10 Shell (org.eclipse.swt.widgets.Shell)9 IEditorReference (org.eclipse.ui.IEditorReference)9 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)8 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)8 IProject (org.eclipse.core.resources.IProject)8