private File extractAbsolutePathFromSelection(StructuredSelection selection) { File result = null; if (selection.getFirstElement() instanceof IFile) { IFile commandFile = (IFile) selection.getFirstElement(); result = new File(commandFile.getLocation().toOSString()); } return result; }
/** Test the receiver against the selected property */ @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { // Ensure Papyrus is the active editor IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if ((editor == null) || (!(editor instanceof IMultiDiagramEditor))) { return false; } Object currentValue = null; if (IS_CALL_ACTION.equals(property)) { if (receiver instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) receiver; Object obj = structuredSelection.getFirstElement(); EObject element = null; if (obj instanceof IAdaptable) { element = (EObject) ((IAdaptable) obj).getAdapter(EObject.class); if (element instanceof View) { element = ((View) element).getElement(); } } currentValue = element instanceof InvocationAction; } return (currentValue == expectedValue); } return false; }
/** * @return the {@link #getViewerWidget()} current selections first element or <code>null</code> * @since 3.2.0 */ public Object getViewerWidgetFirstSelection() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection == null || selection.size() == 0) { return null; } return selection.getFirstElement(); }
public void testModelChanged(TestModelChange change) { switch (change.getKind()) { case TestModelChange.INSERT: doInsert(change); break; case TestModelChange.REMOVE: doRemove(change); break; case TestModelChange.STRUCTURE_CHANGE: doStructureChange(change); break; case TestModelChange.NON_STRUCTURE_CHANGE: doNonStructureChange(change); break; default: throw new IllegalArgumentException("Unknown kind of change"); } StructuredSelection selection = new StructuredSelection(change.getChildren()); if ((change.getModifiers() & TestModelChange.SELECT) != 0) { ((StructuredViewer) fViewer).setSelection(selection); } if ((change.getModifiers() & TestModelChange.REVEAL) != 0) { Object element = selection.getFirstElement(); if (element != null) { ((StructuredViewer) fViewer).reveal(element); } } }
/** @see ActionDelegate#run(IAction) */ public void run(IAction action) { if (this.selection instanceof StructuredSelection) { StructuredSelection selection = (StructuredSelection) this.selection; if (!selection.isEmpty()) { IWorkbench workbench = PlatformUI.getWorkbench(); Shell shell = workbench.getActiveWorkbenchWindow().getShell(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); InputDialog inputDialog = new InputDialog( Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell(), "Ingreso de version", "Ingrese la version a generar", "", null); int manual = inputDialog.open(); if (manual == 0) { String value = inputDialog.getValue(); IFolder folder = (IFolder) selection.getFirstElement(); try { IFolder folder1 = folder.getFolder(new Path(value)); folder1.create(true, false, new NullProgressMonitor()); IFile file = folder1.getFile(new Path("000_db_version_insert.sql")); file.create( new ByteArrayInputStream(VERSION_SCRIPT.replace("DBVERSION", value).getBytes()), true, new NullProgressMonitor()); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
private IModelNode getFirstElementInSelection() { StructuredSelection currentSelection = (StructuredSelection) getSelection(); if (currentSelection == null || currentSelection.isEmpty()) { return null; } return (IModelNode) currentSelection.getFirstElement(); }
@Override public boolean test() throws Exception { StructuredSelection eventsTableSelection = getEventsTableSelection(); if (eventsTableSelection.isEmpty()) { return false; } fCurValue = ((ITmfEvent) eventsTableSelection.getFirstElement()).getTimestamp().getValue(); return fCurValue == fSelectionTime; }
@Override public void doubleClick(final DoubleClickEvent event) { final Playlist playlist = player.getPlaylist(); if (!playlist.isEmpty()) { final StructuredSelection selection = (StructuredSelection) event.getSelection(); playlist.setCurrentTrack((PlaylistItem) selection.getFirstElement()); player.play(); event.getViewer().refresh(); } }
/** {@inheritDoc} */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); AbstractRootEditor rootEditor = (AbstractRootEditor) HandlerUtil.getActiveEditor(event); RepositoryDefinition repositoryDefinition = rootEditor.getInputDefinition().getRepositoryDefinition(); Object selectedObject = selection.getFirstElement(); ExceptionSensorData dataToNavigateTo = null; if (selectedObject instanceof ExceptionSensorData) { dataToNavigateTo = (ExceptionSensorData) selectedObject; } else if (selectedObject instanceof InvocationSequenceData) { List<ExceptionSensorData> exceptions = ((InvocationSequenceData) selectedObject).getExceptionSensorDataObjects(); if ((null != exceptions) && !exceptions.isEmpty()) { for (ExceptionSensorData exSensorData : exceptions) { if (0 != exSensorData.getMethodIdent()) { dataToNavigateTo = exSensorData; break; } } } } if (null != dataToNavigateTo) { ExceptionSensorData exceptionSensorData = dataToNavigateTo; // exit if the object does not carry the methodIdent if (null == exceptionSensorData.getThrowableType()) { return null; } InputDefinition inputDefinition = getInputDefinition(repositoryDefinition, exceptionSensorData); // open the view via command IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand(OpenViewHandler.COMMAND); ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, new Event()); IEvaluationContext context = (IEvaluationContext) executionEvent.getApplicationContext(); context.addVariable(OpenViewHandler.INPUT, inputDefinition); try { command.executeWithChecks(executionEvent); } catch (NotDefinedException | NotEnabledException | NotHandledException e) { throw new ExecutionException("Error opening the exception type view.", e); } } return null; }
/* (non-Javadoc) * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#appliesTo(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ public boolean appliesTo(IWorkbenchPart part, ISelection selection) { Object object = null; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; object = structuredSelection.getFirstElement(); if (object instanceof XSDConcreteComponent || object instanceof Element) { return true; } } return false; }
/** * Handle the selection changed event. This won't do anything unless both a selection occured and * the mouse or key was pressed. */ public void handleSelectionChanged() { if (selectionChangedEvent != null && mouseOrKeyPressed) { StructuredSelection s = (StructuredSelection) selectionChangedEvent.getSelection(); s.getFirstElement(); assert (s.getFirstElement() instanceof SelectableElement); SelectableElement element = (SelectableElement) s.getFirstElement(); switchCheckType(element); setSelectedTypeForChildren(element); setSelectedTypeForParent(element); viewer.refresh(); // reset since processed selectionChangedEvent = null; mouseOrKeyPressed = false; } }
/** * Get a {@link ITeiidServer} from the given selection if one can be adapted * * @param selection * @return server or null */ public static ITeiidServer getServerFromSelection(ISelection selection) { if (selection == null || !(selection instanceof StructuredSelection)) return null; if (selection.isEmpty()) { return null; } StructuredSelection ss = (StructuredSelection) selection; Object element = ss.getFirstElement(); return adapt(element, ITeiidServer.class); }
private void deleteSelection() { if (viewer.getTable().getSelectionIndex() == -1) { return; } StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection.getFirstElement() instanceof GlobalProperty) { GlobalProperty property = (GlobalProperty) selection.getFirstElement(); String file = property.holderFile; if (file != null) { File f = new File(file); if (!(f.exists() && f.isFile())) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.NotFile.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.NotFile.Message", //$NON-NLS-1$ new Object[] {file})); return; } else if (!f.canWrite()) { MessageDialog.openError( getShell(), Messages.getString("ResourceEditDialog.ReadOnlyEncounter.Title"), // $NON-NLS-1$ Messages.getFormattedString( "ResourceEditDialog.ReadOnlyEncounter.Message", //$NON-NLS-1$ new Object[] {file})); return; } } // if the file is read-only then change is not allowed. listChanged = true; if (property.holderFile != null) property.isDeleted = true; else globalLinkedProperties.remove(property); viewer.refresh(); updateSelection(); } }
/** * @param selection * @return first element of the selection */ public static Object getFirstSelectedElement(ISelection selection) { if (selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; return treeSelection.getFirstElement(); } else if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; return structuredSelection.getFirstElement(); } else if (selection instanceof IFileEditorInput) { IFileEditorInput editorInput = (FileEditorInput) selection; return editorInput.getFile(); } else if (selection instanceof TextSelection) { return null; } else { throw new RuntimeException(Messages.GeneratorUtils_SelectionNotSupported); } }
@Override public void setSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; if (sel.isEmpty()) productTypeGUIList.setSelection(-1); else { ProductType spi = (ProductType) sel.getFirstElement(); int idx = 0; for (Iterator it = productTypeItemList.iterator(); it.hasNext(); ++idx) { ProductType pi = (ProductType) it.next(); if (spi.getPrimaryKey().equals(pi.getPrimaryKey())) { productTypeGUIList.setSelection(idx); break; } } } } }
public Object execute(ExecutionEvent event) throws ExecutionException { StructuredSelection mainViewSelection = (StructuredSelection) PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getSelectionService() .getSelection("de.berlios.quotations.ui.MainView"); if (!mainViewSelection.isEmpty()) { Quotation quotation = (Quotation) mainViewSelection.getFirstElement(); if (quotation.getId() != null) { if (MessageBoxes.question(Messages.getString("DeleteRecordAction.Question")) == SWT.YES) { //$NON-NLS-1$ Activator.getDB().deleteById(quotation.getId()); Activator.refresh(); } } } return null; }
@Override public void init(ICommonActionExtensionSite site) { if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { StructuredSelection selection = (StructuredSelection) site.getStructuredViewer().getSelection(); Object fe = selection.getFirstElement(); if (fe instanceof IRepositoryNode) { IRepositoryViewObject object = ((IRepositoryNode) fe).getObject(); if (object instanceof TdTableRepositoryObject) { TdTableRepositoryObject tableObject = (TdTableRepositoryObject) object; modelElement = tableObject.getTdTable(); } else if (object instanceof TdViewRepositoryObject) { TdViewRepositoryObject viewObject = (TdViewRepositoryObject) object; modelElement = viewObject.getTdView(); } } } super.init(site); }
private void doInsert() { try { final StructuredSelection sel = (StructuredSelection) viewer.getSelection(); if (sel == null) return; final IVariable var = (IVariable) sel.getFirstElement(); final IDocument doc = getTextViewer().getDocument(); final String rep = "${" + var.getVariableName() + "}"; if (currentSelectedText != null) { final int total = currentSelectedText.getOffset() + currentSelectedText.getLength(); int len = currentSelectedText.getLength(); final int tLen = doc.getLength(); if (total > tLen) len = tLen - currentSelectedText.getOffset(); if (len < 0) len = 0; doc.replace(currentSelectedText.getOffset(), len, rep); } } catch (BadLocationException e) { logger.error("Cannot replace selection " + getTextViewer().getSelectedRange(), e); } }
/** @return the selected pictogram element. */ protected PictogramElement getSelectedPictogramElement() { if (getSelection() instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) getSelection(); Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof PictogramElement) { return (PictogramElement) firstElement; } EditPart editPart = null; if (firstElement instanceof EditPart) { editPart = (EditPart) firstElement; } else if (firstElement instanceof IAdaptable) { editPart = (EditPart) ((IAdaptable) firstElement).getAdapter(EditPart.class); } if (editPart != null && editPart.getModel() instanceof PictogramElement) { return (PictogramElement) editPart.getModel(); } } return null; }
@Override protected void buttonPressed(int buttonId) { if (buttonId == 0) { StructuredSelection ss = (StructuredSelection) this.list.getSelection(); IProject project = (IProject) ss.getFirstElement(); path = project.getLocation().toString(); File fileToRead = new File(path + File.separator + "config.xml"); try { Config config = Config.loadXml(new FileInputStream(fileToRead)); id = config.getId(); } catch (FileNotFoundException e) { e.printStackTrace(); } initInfo(); compileLoader(id); close(); } else if (buttonId == 1) { close(); } }
/* * (non-Javadoc) * * @see org.eclipse.jface.wizard.Wizard#performFinish() */ @Override public boolean performFinish() { if (mainPage.isCreateNewVersionJob()) { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(final IProgressMonitor monitor) throws CoreException { if (!alreadyEditedByUser) { getProperty().setVersion(mainPage.getNewVersion()); refreshNewJob(); try { ProxyRepositoryFactory.getInstance() .saveProject(ProjectManager.getInstance().getCurrentProject()); } catch (Exception e) { ExceptionHandler.process(e); } } try { ProxyRepositoryFactory.getInstance().lock(repoObject); } catch (PersistenceException e) { ExceptionHandler.process(e); } catch (LoginException e) { ExceptionHandler.process(e); } boolean locked = repoObject.getRepositoryStatus().equals(ERepositoryStatus.LOCK_BY_USER); openAnotherVersion((RepositoryNode) repoObject.getRepositoryNode(), !locked); try { ProxyRepositoryFactory.getInstance() .saveProject(ProjectManager.getInstance().getCurrentProject()); } catch (Exception e) { ExceptionHandler.process(e); } } }; IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { ISchedulingRule schedulingRule = workspace.getRoot(); // the update the project files need to be done in the workspace // runnable to avoid all notification // of changes before the end of the modifications. workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null); } catch (CoreException e) { MessageBoxExceptionHandler.process(e); } } else { StructuredSelection selection = (StructuredSelection) mainPage.getSelection(); RepositoryNode node = (RepositoryNode) selection.getFirstElement(); boolean lastVersion = node.getObject().getVersion().equals(repoObject.getVersion()); repoObject.getProperty().setVersion(originalVersion); if (lastVersion) { lockObject(repoObject); } ERepositoryStatus status = node.getObject().getRepositoryStatus(); boolean isLocked = false; if (status == ERepositoryStatus.LOCK_BY_USER) { isLocked = true; } // Only latest version can be editted openAnotherVersion(node, !lastVersion || !isLocked); } return true; }
public VMTreeObject GetSelectedObject() { StructuredSelection select = (StructuredSelection) viewer.getSelection(); VMTreeObject element = (VMTreeObject) select.getFirstElement(); return element; }
public void run() { ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.size() == 1) { if (structuredSelection.getFirstElement() instanceof IFile) { IFile implementationNote = (IFile) structuredSelection.getFirstElement(); if (implementationNote.getFileExtension().equals("int")) { InputStream inStream; try { inStream = implementationNote.getContents(); long byteCount = implementationNote.getRawLocation().toFile().length(); byte[] byteArray = new byte[(int) byteCount]; inStream.read(byteArray); IDocument document = new Document(new String(byteArray)); FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document); IRegion startRegion = frda.find(0, "8. Code Changes", true, true, true, false); int startOffset = startRegion.getOffset() + 17; IRegion endRegion = frda.find(startOffset, "End", true, true, true, false); int endOffset = endRegion.getOffset(); String fileList = document.get(startOffset, endOffset - startOffset); fileList = fileList.replaceAll("---------------\r\n", ""); fileList = fileList.replaceAll("Branch name:.*\r\n", ""); fileList = fileList.replaceAll("\r\n ", ""); fileList = fileList.replaceAll("\r\n", ","); fileList = fileList.replaceAll(">", ""); String[] filesString = fileList.split(","); if (filesString.length == 0) return; ArrayList<IFile> list = new ArrayList<IFile>(); for (int i = 0; i < filesString.length; i++) { if (!filesString[i].equals("")) { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filesString[i]); if (resource instanceof IFile) { list.add((IFile) resource); } } } if (list.size() == 0) return; IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); String workingSetName = "chgset-" + implementationNote.getName().replaceAll(".int", ""); IWorkingSet set = workingSetManager.createWorkingSet( workingSetName, list.toArray(new IFile[list.size()])); IWorkingSet existingSet = workingSetManager.getWorkingSet(workingSetName); if (existingSet != null) { workingSetManager.removeWorkingSet(existingSet); } workingSetManager.addWorkingSet(set); inStream.close(); } catch (CoreException e) { } catch (IOException e) { } catch (BadLocationException e) { } } } } } }