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);
}
}
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;
}
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);
}
}
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();
}
});
}
});
}
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;
}
Aggregations