Java Code Examples for org.eclipse.ui.handlers.HandlerUtil#getActiveWorkbenchWindow()
The following examples show how to use
org.eclipse.ui.handlers.HandlerUtil#getActiveWorkbenchWindow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteEditorFileHandler.java From eclipse-extras with Eclipse Public License 1.0 | 6 votes |
@Override public Object execute( ExecutionEvent event ) { IEditorInput editorInput = HandlerUtil.getActiveEditorInput( event ); IFile resource = ResourceUtil.getFile( editorInput ); if( resource != null ) { if( resource.isAccessible() ) { deleteResource( HandlerUtil.getActiveWorkbenchWindow( event ), resource ); } } else { File file = getFile( editorInput ); IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow( event ); if( file != null && prompter.confirmDelete( workbenchWindow, file )) { deleteFile( workbenchWindow, file ); } } return null; }
Example 2
Source File: CallEditor.java From codeexamples-eclipse with Eclipse Public License 1.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // get the page IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); // get the selection ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection != null && selection instanceof IStructuredSelection) { Object obj = ((IStructuredSelection) selection).getFirstElement(); // if we had a selection lets open the editor if (obj != null) { Task todo = (Task) obj; TaskEditorInput input = new TaskEditorInput(todo.getId()); try { page.openEditor(input, TaskEditor.ID); } catch (PartInitException e) { throw new RuntimeException(e); } } } return null; }
Example 3
Source File: NextEditorHandler.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); if (activeWorkbenchWindow == null) { return null; } IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage == null) { return null; } switchEditor(activePage, next()); return null; }
Example 4
Source File: PreferenceHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window != null) { PreferenceUtil.openPreferenceDialog(window, null); } return null; }
Example 5
Source File: NewTMHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); NewTmDbWizard wizard = new NewTmDbWizard(); ImportTmxWizardDialog dialog = new ImportTmxWizardDialog(window.getShell(), wizard); dialog.open(); return null; }
Example 6
Source File: NewTBHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); NewTermDbWizard wizard = new NewTermDbWizard(); TermDbManagerImportWizardDialog dialog = new TermDbManagerImportWizardDialog(window.getShell(), wizard); dialog.open(); return null; }
Example 7
Source File: TermDbManageHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); TermDbManagerDialog dialog = new TermDbManagerDialog(window.getShell()); dialog.setDialogUseFor(TermDbManagerDialog.TYPE_DBMANAGE); dialog.open(); return null; }
Example 8
Source File: NewTBHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { 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(NewTBHandler.class).error("Exception:key hs008 is lost.(Can't find the key)"); System.exit(0); } IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); NewTermDbWizard wizard = new NewTermDbWizard(); TermDbManagerImportWizardDialog dialog = new TermDbManagerImportWizardDialog(window.getShell(), wizard); dialog.open(); return null; }
Example 9
Source File: BillingProposalViewCreateBillsHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private BillingProposalView getOpenView(ExecutionEvent event){ try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); return (BillingProposalView) page.showView(BillingProposalView.ID); } catch (PartInitException e) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler", "Konnte Rechnungs-Vorschlag View nicht öffnen"); } return null; }
Example 10
Source File: PrintBillingProposalHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private BillingProposalView getOpenView(ExecutionEvent event){ try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); return (BillingProposalView) page.showView(BillingProposalView.ID); } catch (PartInitException e) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler", "Konnte Rechnungs-Vorschlag View nicht öffnen"); } return null; }
Example 11
Source File: ExecuteGoogleTransHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * (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; } PrefrenceParameters ps = PrefrenceParameters.getInstance(); if (!ps.isGoogleState()) { MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteGoogleTransHandler.msgTitle"), Messages.getString("handler.ExecuteGoogleTransHandler.msg")); return null; } final IXliffEditor xliffEditor = (IXliffEditor) editor; final int[] selectedRowIndexs = xliffEditor.getSelectedRows(); if (selectedRowIndexs.length == 0) { return null; } ISimpleMatcher matcher = new SimpleMatcherGoogleImpl(); IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID); if (viewPart != null && viewPart instanceof MatchViewPart) { MatchViewPart matchView = (MatchViewPart) viewPart; matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher); } return null; }
Example 12
Source File: ExecuteBingTransHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * (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.isBingState()) { MessageDialog.openError(window.getShell(), Messages.getString("handler.ExecuteBingTransHandler.msgTitle"), Messages.getString("handler.ExecuteBingTransHandler.msg")); return null; } final IXliffEditor xliffEditor = (IXliffEditor) editor; final int[] selectedRowIndexs = xliffEditor.getSelectedRows(); if (selectedRowIndexs.length == 0) { return null; } ISimpleMatcher matcher = new SimpleMatcherBingImpl(); IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID); if (viewPart != null && viewPart instanceof MatchViewPart) { MatchViewPart matchView = (MatchViewPart) viewPart; matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher); } return null; }
Example 13
Source File: TermDbManageHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { 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(TermDbManageHandler.class).error("Exception:key hs008 is lost.(Can't find the key)"); System.exit(0); } SystemResourceUtil.load(); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); TermDbManagerDialog dialog = new TermDbManagerDialog(window.getShell()); dialog.setDialogUseFor(TermDbManagerDialog.TYPE_DBMANAGE); dialog.open(); return null; }
Example 14
Source File: StartBillingProposalHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private BillingProposalView getOpenView(ExecutionEvent event){ try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); return (BillingProposalView) page.showView(BillingProposalView.ID); } catch (PartInitException e) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler", "Konnte Rechnungs-Vorschlag View nicht öffnen"); } return null; }
Example 15
Source File: RefreshBillingProposalViewHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private BillingProposalView getOpenView(ExecutionEvent event){ try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); return (BillingProposalView) page.showView(BillingProposalView.ID); } catch (PartInitException e) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler", "Konnte Rechnungs-Vorschlag View nicht öffnen"); } return null; }
Example 16
Source File: CreatePieChartHandler.java From slr-toolkit with Eclipse Public License 1.0 | 4 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // TODO: seems to be there is some refactoring needed in here ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection == null || !(selection instanceof IStructuredSelection)) { return null; } IStructuredSelection currentSelection = (IStructuredSelection) selection; IViewPart part = null; try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { part = page.showView(chartViewId); } } } catch (PartInitException e) { e.printStackTrace(); return null; } if (part instanceof ICommunicationView) { view = (ICommunicationView) part; } else { return null; } view.getPreview().setTextToShow(noDataToDisplay); if (currentSelection.size() == 1) { view.getPreview().setDataPresent(true); ChartDataProvider provider = new ChartDataProvider(); Term input = (Term) currentSelection.getFirstElement(); Map<String, Integer> citeChartData = provider.calculateNumberOfPapersPerClass(input); PieChartConfiguration.get().getGeneralSettings().setChartTitle("Number of cites per subclass of " + input.getName()); PieChartConfiguration.get().setPieTermSort(TermSort.SUBCLASS); Chart citeChart = ChartGenerator.createPie(citeChartData); view.setAndRenderChart(citeChart); } else { view.setAndRenderChart(null); } return null; }
Example 17
Source File: CreateBubbleChartHandler.java From slr-toolkit with Eclipse Public License 1.0 | 4 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // TODO: seems to be there is some refactoring needed in here ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection == null || !(selection instanceof IStructuredSelection)) { return null; } IStructuredSelection currentSelection = (IStructuredSelection) selection; IViewPart part = null; try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { part = page.showView(chartViewId); } } } catch (PartInitException e) { e.printStackTrace(); return null; } if (part instanceof ICommunicationView) { view = (ICommunicationView) part; } else { return null; } view.getPreview().setTextToShow(noDataToDisplay); if (currentSelection.size() == 2) { view.getPreview().setDataPresent(true); ChartDataProvider provider = new ChartDataProvider(); @SuppressWarnings("unchecked") Iterator<Term> selectionIterator = currentSelection.iterator(); Term first = selectionIterator.next(); Term second = selectionIterator.next(); List<BubbleDataContainer> bubbleChartData = provider.calculateBubbleChartData(first, second); BubbleChartConfiguration.get().getGeneralSettings().setChartTitle("Intersection of " + first.getName() + " and " + second.getName()); Chart bubbleChart = ChartGenerator.createBubble(bubbleChartData,first,second); view.setAndRenderChart(bubbleChart); } else { view.setAndRenderChart(null); } return null; }
Example 18
Source File: ExecuteQuickTranslation.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** (non-Javadoc) * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ public Object execute(ExecutionEvent event) throws ExecutionException { if(TranslateParameter.getInstance().isAutoQuickTrans()){ return null; } final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); final IEditorPart editor = HandlerUtil.getActiveEditor(event); if (!(editor instanceof IXliffEditor)) { return null; } final IXliffEditor xliffEditor = (IXliffEditor) editor; final int[] selectedRowIndexs = xliffEditor.getSelectedRows(); if(selectedRowIndexs.length == 0){ return null; } // TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(selectedRowIndexs[selectedRowIndexs.length - 1]); IComplexMatch matcher = new QuickTranslationImpl(); // FileEditorInput input = (FileEditorInput) editor.getEditorInput(); // IProject project = input.getFile().getProject(); // List<AltTransBean> newAltTrans = matcher.executeTranslation(transUnitBean, project); // if(newAltTrans.size() == 0){ // return null; // } IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID); if(viewPart != null && viewPart instanceof MatchViewPart){ MatchViewPart matchView = (MatchViewPart) viewPart; matchView.manualExecComplexTranslation(matcher); // matchView.replaceMatchs(newAltTrans); // matchView.refreshView(xliffEditor, selectedRowIndexs[selectedRowIndexs.length - 1]); } // IRunnableWithProgress runnable = new IRunnableWithProgress() { // public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // monitor.beginTask(Messages.getString("handler.ExecuteQuickTranslation.task1"), selectedRowIndexs.length); // IComplexMatch matcher = new QuickTranslationImpl(); // // FileEditorInput input = (FileEditorInput) editor.getEditorInput(); // IProject project = input.getFile().getProject(); // // List<String> oldToolIds = new ArrayList<String>(); // oldToolIds.add(matcher.getToolId()); // Map<Integer, List<AltTransBean>> newAltTransMap = new HashMap<Integer, List<AltTransBean>>(); // Map<Integer, List<String>> oldAltTransToolIdMap = new HashMap<Integer, List<String>>(); // for(int selectedRowindex : selectedRowIndexs){ // TransUnitBean transUnitBean = xliffEditor.getRowTransUnitBean(selectedRowindex); // List<AltTransBean> newAltTrans = matcher.executeTranslation(transUnitBean, project); // if(newAltTrans.size() == 0){ // continue; // } // newAltTransMap.put(selectedRowindex, newAltTrans); // oldAltTransToolIdMap.put(selectedRowindex, oldToolIds); // monitor.worked(1); // } // if(newAltTransMap.size() != 0){ // xliffEditor.getXLFHandler().batchUpdateAltTrans(selectedRowIndexs, newAltTransMap, oldAltTransToolIdMap); // // window.getShell().getDisplay().asyncExec(new Runnable() { // @Override // public void run() { // IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID); // if(viewPart != null && viewPart instanceof MatchViewPart && selectedRowIndexs.length != 0){ // MatchViewPart matchView = (MatchViewPart) viewPart; // matchView.refreshView(xliffEditor, selectedRowIndexs[selectedRowIndexs.length - 1]); // } // } // }); // } // monitor.done(); // } // }; // try { // new ProgressMonitorDialog(window.getShell()).run(true, false, runnable); // } catch (InvocationTargetException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } return null; }
Example 19
Source File: CreateCiteHandler.java From slr-toolkit with Eclipse Public License 1.0 | 4 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // TODO: seems to be there is some refactoring needed in here ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection == null || !(selection instanceof IStructuredSelection)) { return null; } IStructuredSelection currentSelection = (IStructuredSelection) selection; IViewPart part = null; try { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { part = page.showView(chartViewId); } } } catch (PartInitException e) { e.printStackTrace(); return null; } if (part instanceof ICommunicationView) { view = (ICommunicationView) part; } else { return null; } view.getPreview().setTextToShow(noDataToDisplay); if (currentSelection.size() == 1) { view.getPreview().setDataPresent(true); ChartDataProvider provider = new ChartDataProvider(); Term input = (Term) currentSelection.getFirstElement(); Map<String, Integer> citeChartData = provider.calculateNumberOfPapersPerClass(input); BarChartConfiguration.get().getGeneralSettings().setChartTitle("Number of cites per subclass of " + input.getName()); BarChartConfiguration.get().setTermSort(TermSort.SUBCLASS); Chart citeChart = ChartGenerator.createCiteBar(citeChartData); view.setAndRenderChart(citeChart); } else { view.setAndRenderChart(null); } return null; }
Example 20
Source File: ExecuteBingTransHandler.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * (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; }