List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.google.dart.tools.ui.internal.libraryview.LibraryExplorerPart.java
License:Open Source License
public void refresh(IStructuredSelection selection) { Object[] selectedElements = selection.toArray(); for (Object object : selectedElements) { viewer.refresh(object);//from w w w .j av a 2s .c o m } }
From source file:com.google.dart.tools.ui.internal.util.DartUIHelp.java
License:Open Source License
/** * Creates and returns a help context provider for the given part. * // ww w .ja va2 s .c om * @param part the part for which to create the help context provider * @param contextId the optional context ID used to retrieve static help * @return the help context provider */ public static IContextProvider getHelpContextProvider(IWorkbenchPart part, String contextId) { IStructuredSelection selection; try { selection = SelectionConverter.getStructuredSelection(part); } catch (DartModelException ex) { DartToolsPlugin.log(ex); selection = StructuredSelection.EMPTY; } Object[] elements = selection.toArray(); return new JavaUIHelpContextProvider(contextId, elements); }
From source file:com.google.eclipse.javascript.jstestdriver.ui.launch.JsTestDriverLaunchShortcut.java
License:Apache License
@Override public void launch(ISelection selection, String mode) { if (selection instanceof IStructuredSelection) { try {//from w w w .ja v a 2 s .c om IStructuredSelection structuredSelection = (IStructuredSelection) selection; List<String> testCases = new ArrayList<String>(); String projectName = ""; List<IFile> files = new ArrayList<IFile>(); for (Object object : structuredSelection.toArray()) { if (object instanceof IFile) { IFile file = (IFile) object; files.add(file); projectName = file.getProject().getName(); testCases.addAll(finder.getTestCases(file.getLocation().toFile())); } } runTests(projectName, testCases); } catch (CoreException e) { logger.log(Level.SEVERE, "", e); } catch (IOException e) { logger.log(Level.SEVERE, "", e); } } }
From source file:com.halware.nakedide.eclipse.ext.annot.action.NakedObjectActionsView.java
License:Open Source License
public void resetView(CompilationUnit root, IStructuredSelection selectionHint) { // select in action table. Will also setInput on params view. super.resetView(root, selectionHint); if (selectionHint == null) { return;//ww w . j av a 2 s .co m } // now select in params view using the 2nd element in the structured selection, if available. Object[] selections = selectionHint.toArray(); if (selections.length != 2 || !(selections[1] instanceof NakedObjectActionParameter)) { return; } NakedObjectActionParameter nakedObjectActionParameter = (NakedObjectActionParameter) selections[1]; SingleVariableDeclaration searchDeclaration = (SingleVariableDeclaration) nakedObjectActionParameter .getDeclaration(); CompilationUnit parsedCompilationUnit = getEditorTracker().getParsedCompilationUnit(); if (parsedCompilationUnit == null) { return; } SingleVariableDeclaration newDeclaration = AstUtils.findDeclaration(parsedCompilationUnit, searchDeclaration); if (newDeclaration == null) { return; } AbstractNode<ASTNode> node = find(parsedCompilationUnit, newDeclaration); if (node != null) { paramsViewer.setSelection(new StructuredSelection(new Object[] { node }), true); } }
From source file:com.hangum.tadpole.manager.core.editor.schemahistory.SchemaHistoryEditor.java
License:Open Source License
/** * history compare/* ww w.ja va2s .co m*/ */ private void compare() { IStructuredSelection ss = (IStructuredSelection) tableViewer.getSelection(); if (!ss.isEmpty()) { Object[] objListSel = ss.toArray(); try { for (int i = 0; i < objListSel.length; i++) { if (i == 2) break; SchemaHistoryDAO dao = (SchemaHistoryDAO) objListSel[i]; String strSQL = getSQL(dao.getSeq()); if (i == 0) { textDateLeft.setText(dao.getCreate_date().toLocaleString()); textLeftSQL.setText(strSQL); } else { textDateRight.setText(dao.getCreate_date().toLocaleString()); textSQLRight.setText(strSQL); } } } catch (Exception e) { logger.error("Get detail sql", e); } if (objListSel.length == 1) { textDateRight.setText(""); textSQLRight.setText(""); } } else { textDateLeft.setText(""); textLeftSQL.setText(""); textDateRight.setText(""); textSQLRight.setText(""); } }
From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.ObjectExplorerSelectionAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection, UserDBDAO userDB, OBJECT_TYPE actionType) { if (selection.isEmpty()) return;/* www .ja v a 2s. c om*/ String strObjectName = ""; Object[] arryObj = selection.toArray(); // table dao if (arryObj[0] instanceof TableDAO) { for (int i = 0; i < arryObj.length; i++) { TableDAO tcDAO = (TableDAO) arryObj[i]; strObjectName += tcDAO.getFullName() + ", "; //$NON-NLS-1$ } // column dao } else { for (int i = 0; i < arryObj.length; i++) { TableColumnDAO tcDAO = (TableColumnDAO) arryObj[i]; strObjectName += tcDAO.getField() + ", "; //$NON-NLS-1$ } } strObjectName = StringUtils.removeEnd(strObjectName, ", "); //$NON-NLS-1$ FindEditorAndWriteQueryUtil.runAtPosition(strObjectName); }
From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.ObjectExplorerSelectionToEditorAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection, UserDBDAO userDB, OBJECT_TYPE actionType) { if (selection.isEmpty()) return;//from w ww . j av a 2 s. co m String strObjectName = ""; Object[] arryObj = selection.toArray(); if (arryObj[0] instanceof StructObjectDAO) { for (int i = 0; i < arryObj.length; i++) { StructObjectDAO tcDAO = (StructObjectDAO) arryObj[i]; strObjectName += tcDAO.getFullName() + ", "; //$NON-NLS-1$ } } strObjectName = StringUtils.removeEnd(strObjectName, ", "); //$NON-NLS-1$ FindEditorAndWriteQueryUtil.runAtPosition(strObjectName); }
From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.TableColumnSelectionAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection, UserDBDAO userDB, DB_ACTION actionType) { if (selection.isEmpty()) return;//from www . j a v a 2 s . c om String strColumnName = ""; Object[] arryObj = selection.toArray(); for (int i = 0; i < arryObj.length; i++) { Object obj = arryObj[arryObj.length - i - 1]; TableColumnDAO tcDAO = (TableColumnDAO) obj; strColumnName += tcDAO.getField() + ", "; //$NON-NLS-1$ } // String strColumnName = ""; // for(Object obj : selection.toArray()) { // TableColumnDAO tcDAO = (TableColumnDAO)obj; // strColumnName += tcDAO.getField() + ", "; //$NON-NLS-1$ // } strColumnName = StringUtils.removeEnd(strColumnName, ", "); //$NON-NLS-1$ FindEditorAndWriteQueryUtil.runAtPosition(strColumnName); }
From source file:com.hudson.hibernatesynchronizer.popup.actions.SynchronizeFiles.java
License:GNU General Public License
/** * @see IActionDelegate#run(IAction)// ww w . ja va 2 s . com */ public void run(IAction action) { Shell shell = new Shell(); final ISelectionProvider provider = part.getSite().getSelectionProvider(); if (null != provider) { if (provider.getSelection() instanceof StructuredSelection) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(part.getSite().getShell()); try { dialog.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { IStructuredSelection selection = (StructuredSelection) provider.getSelection(); monitor.beginTask("Synchronizing files...", 2 + (selection.toArray().length * 14)); exec(selection, monitor); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }); } catch (Exception e) { } } } }
From source file:com.hudson.hibernatesynchronizer.popup.actions.SynchronizeFiles.java
License:GNU General Public License
private void exec(IStructuredSelection selection, IProgressMonitor monitor) { Shell shell = new Shell(); Object[] obj = selection.toArray(); HibernateDOMParser domParser = null; Map fileMap = new HashMap(); IProject project = null;//from w w w . ja v a 2s . c om Map documents = new HashMap(); for (int i = 0; i < obj.length && !monitor.isCanceled(); i++) { if (obj[i] instanceof IFile) { IFile file = (IFile) obj[i]; HibernateEditor.initFile(file); project = file.getProject(); try { monitor.subTask(file.getName() + ": creating DOM"); domParser = new HibernateDOMParser(file.getContents()); Document doc = domParser.getDocument(); HibernateDocument hd = DOMHelper.getHibernateDocument(domParser, file.getProject()); documents.put(file, hd); List classes = hd.getClasses(); HibernateEditor.cache(file.getProject(), file.getFullPath().toFile(), classes); monitor.worked(1); } catch (SAXParseException e) { EditorUtil.addProblemMarker(file, e.getMessage(), e.getLineNumber()); } catch (NoRouteToHostException nrthe) { EditorUtil.addProblemMarker(file, "This is not synchronized with the Java model. A NoRouteToHostException occured while process the synchronization. Either remove the external namespace and DTD definitions or connect to the internet (or configure your proxy).", 1); MessageDialog.openError(shell, "An error has occured: NoRouteToHostException", "This usually occurs if you have namespace references or DTD validation and are either not connected to the internet or do not have your proxy setting correctly configured.\n\nPlease resolve these issues to use the HibernateSynchronizer plugin."); } catch (Throwable e) { EditorUtil.addProblemMarker(file, e.getMessage(), 1); MessageDialog.openError(shell, "An error has occured", e.getMessage()); Plugin.logError(e); } } } if (null == project) return; boolean valid = true; try { IJavaProject javaProject = JavaCore.create(project); IPackageFragmentRoot root = HSUtil.getProjectRoot(javaProject); if (valid && null != root) { Object contextObject = null; String customObjectStr = Plugin.getProperty(javaProject.getProject(), Constants.PROP_CONTEXT_OBJECT); if (null != customObjectStr && customObjectStr.trim().length() > 0) { ClassLoader loader = new ProjectClassLoader(javaProject, getClass().getClassLoader()); try { contextObject = loader.loadClass(customObjectStr).newInstance(); } catch (Exception e) { } } Context context = SynchronizerThread.getDefaultContext(null, javaProject, contextObject); try { Snippet snippet = TemplateManager.getInstance().findSnippetByName("Setup", javaProject.getProject()); if (null != snippet) { StringWriter sw = new StringWriter(); Constants.customGenerator.evaluate(context, sw, Velocity.class.getName(), snippet.getContent()); String trimmed = sw.toString().trim(); if (trimmed.startsWith(SynchronizerThread.WARNING)) { String message = trimmed.substring(SynchronizerThread.WARNING.length(), trimmed.length()); MessageDialog.openWarning(shell, "Warning", message); } else if (trimmed.startsWith(SynchronizerThread.ERROR)) { String message = trimmed.substring(SynchronizerThread.ERROR.length(), trimmed.length()); MessageDialog.openError(shell, "An error has occured", message); valid = false; } else if (trimmed.startsWith(SynchronizerThread.FATAL)) { String message = trimmed.substring(SynchronizerThread.FATAL.length(), trimmed.length()); MessageDialog.openError(shell, "An error has occured", message); valid = false; } } } catch (Exception e) { } if (valid) { for (int i = 0; i < obj.length && !monitor.isCanceled(); i++) { if (obj[i] instanceof IFile) { IFile file = (IFile) obj[i]; try { file.deleteMarkers(null, false, 1); monitor.subTask(file.getName() + ": retrieving hibernate class objects"); HibernateDocument hd = (HibernateDocument) documents.get(file); monitor.worked(1); if (null != hd) { List classes = hd.getClasses(); for (Iterator iter = classes.iterator(); iter.hasNext();) { HibernateClass hc = (HibernateClass) iter.next(); fileMap.put(hc, file); if (null == hc.getPackageName() || hc.getPackageName().length() == 0) { valid = false; } } SynchronizerThread.synchronize(javaProject, root, classes, monitor, file.getName(), file, context, force()); } } catch (HibernateSynchronizerException e) { int lineNumber = e.getLineNumber(); if (null != e.getNode() && null != domParser.getLineNumber(e.getNode())) { lineNumber = domParser.getLineNumber(e.getNode()).intValue(); } if (lineNumber <= 0) { lineNumber = 1; } EditorUtil.addProblemMarker(file, e.getMessage(), lineNumber); } catch (Throwable e) { EditorUtil.addProblemMarker(file, e.getMessage(), 1); MessageDialog.openError(shell, "An error has occured", e.getMessage()); Plugin.logError(e); } } } } } } catch (CoreException ce) { Plugin.logError(ce); } }