List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:ca.edchipman.silverstripepdt.wizards.NewSilverStripeTemplatesWizardPage.java
License:Open Source License
/** * Get the currently selected template.//from w ww. j a v a 2 s. c o m * * @return */ private Template getSelectedTemplate() { Template template = null; IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); if (selection.size() == 1) { template = (Template) selection.getFirstElement(); } return template; }
From source file:ca.hc11337.gui.fileselector.HC11337FileSelector.java
License:Open Source License
public HC11337FileSelector(Composite parent, HC11337Controller controller, int style) { fileViewer = new TableViewer(parent, style); TableLayout layout = new TableLayout(); layout.addColumnData(new ColumnWeightData(100, true)); fileViewer.getTable().setLayout(layout); fileViewer.getTable().setHeaderVisible(true); fileViewer.setContentProvider(new FileSelectorContentProvider()); fileViewer.setLabelProvider(new FileSelectorLabelProvider()); fileViewer.setInput(new File("workspace")); class DoubleClickListener implements IDoubleClickListener { private HC11337Controller controller; public DoubleClickListener(HC11337Controller controller) { this.controller = controller; }//from ww w . j a va2s. co m public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); File file = (File) selection.getFirstElement(); if (getExtension(file).equals("asm")) { controller.openFile(file); File binary = new File("workspace/" + getNameMinusExtension(file) + ".s19"); controller.loadBinary(binary); } else controller.loadBinary(file); } private String getNameMinusExtension(File file) { String nameExt = file.getName(); String ext = getExtension(file); return nameExt.substring(0, nameExt.length() - ext.length() - 1); } private String getExtension(File file) { String name = file.getName(); String extension = ""; int i = name.length() - 1; do { extension = name.charAt(i) + extension; i--; } while (name.charAt(i) != '.'); return extension.toLowerCase(); } } fileViewer.addDoubleClickListener(new DoubleClickListener(controller)); TableColumn column1 = new TableColumn(fileViewer.getTable(), SWT.LEFT); column1.setText("Source Files"); }
From source file:ca.mcgill.cs.swevo.ppa.ui.actions.PPAOnCuAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection sSelection = (IStructuredSelection) selection; if (!sSelection.isEmpty()) { icu = (ICompilationUnit) sSelection.getFirstElement(); }//from w ww. ja va 2 s . com }
From source file:ca.mcgill.cs.swevo.ppa.ui.actions.PPAOnFileAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection sSelection = (IStructuredSelection) selection; if (!sSelection.isEmpty()) { file = (IFile) sSelection.getFirstElement(); }/* w w w .j a v a2s . c om*/ }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.pages.CodeEditorPage.java
License:Open Source License
/** * The action to take if remove code is selected (on the tree). * @return/* ww w .ja va 2s . c o m*/ */ private SelectionAdapter removeCodeSelected() { return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); Node node = (Node) selection.getFirstElement(); boolean check = true; if (!node.getChildren().isEmpty()) { check = MessageDialog.openConfirm(getSite().getShell(), Messages.getString("editors.pages.CodeEditorPage.removeCode"), //$NON-NLS-1$ Messages.getString("editors.pages.CodeEditorPage.removeConfirm")); //$NON-NLS-1$ } if (check) { fTreeModel.removeNode(node); fTreeModel.getRoot().computeFreq(); fTreeViewer.refresh(); if (fFilterButton.getSelection()) { fTableViewer.refresh(); } setDirty(); } } }; }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.pages.CodeEditorPage.java
License:Open Source License
/** * The action to take if New Sub-Code is selected (on the tree). * @return/* ww w .j a va2 s. com*/ */ private SelectionListener createSubCodeSelected() { return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); Node node = (Node) selection.getFirstElement(); if (node == null) { return; } NewCodeDialog dialog = new NewCodeDialog(getEditor().getSite().getShell(), fProject); dialog.create(); if (dialog.open() == Window.OK) { Code code = Facade.getInstance().createCode(dialog.getName(), dialog.getDescription(), fProject); CommonNavigator view = (CommonNavigator) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().findView(QualyzerActivator.PROJECT_EXPLORER_VIEW_ID); view.getCommonViewer().refresh(); new Node(node, code.getCodeName(), code.getPersistenceId(), 0); fTreeViewer.refresh(); fTreeViewer.expandToLevel(node, 1); if (fFilterButton.getSelection()) { fTableViewer.refresh(); } setDirty(); } } }; }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.pages.CodeEditorPage.java
License:Open Source License
/** * The action to take on double click on the table. * @return/* ww w .ja va 2 s .com*/ */ private IDoubleClickListener createDoubleClickListenerTable() { return new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); CodeTableRow row = (CodeTableRow) selection.getFirstElement(); Code code = row.getCode(); if (code != null) { ResourcesUtil.openEditor(getSite().getPage(), code); } } }; }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.pages.CodeEditorPage.java
License:Open Source License
/** * The double click action on the tree.//from w ww.j av a 2 s . co m * @return */ private IDoubleClickListener createDoubleClickListenerTree() { return new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { Code toView = null; if (fFilterButton.getSelection()) { Node node = (Node) ((IStructuredSelection) fTreeViewer.getSelection()).getFirstElement(); for (Code aCode : fProject.getCodes()) { if (aCode.getCodeName().equals(node.getCodeName())) { toView = aCode; break; } } } else { IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); toView = ((CodeTableRow) selection.getFirstElement()).getCode(); } if (toView != null) { ResourcesUtil.openEditor(getSite().getPage(), toView); } } }; }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.pages.CodeEditorPage.java
License:Open Source License
/** * The action taken when rename code is selected on the table. * @return// w w w . j a va2 s . c om */ private SelectionListener renameCodeSelected() { return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); Code code = ((CodeTableRow) selection.getFirstElement()).getCode(); RenameCodeDialog dialog = new RenameCodeDialog(getSite().getShell(), code); dialog.open(); if (dialog.getReturnCode() == Window.OK) { String name = dialog.getName(); code.setCodeName(name); Facade.getInstance().saveCodes(new Code[] { code }); CommonNavigator view = (CommonNavigator) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().findView(QualyzerActivator.PROJECT_EXPLORER_VIEW_ID); view.getCommonViewer().refresh(); } } }; }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.pages.CodeEditorPage.java
License:Open Source License
/** * Handles the selection of the Delete Code Action on the table. * Checks if there are any memos stopping the deletion. * Then finds all the fragments that contain the code. * Displays a warning/confirmation.//from w ww .j a v a2s . c om * Removes the code from all associated fragments and then deletes the code. * @return */ private SelectionAdapter deleteCodeSelected() { return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); Code toDelete = ((CodeTableRow) selection.getFirstElement()).getCode(); List<Memo> hardConflicts = detectHardConflicts(toDelete); if (!hardConflicts.isEmpty()) { String message = buildErrorString(hardConflicts); MessageDialog.openError(getSite().getShell(), Messages.getString("editors.pages.CodeEditorPage.unableToDelete"), message); //$NON-NLS-1$ return; } List<Fragment> conflicts = detectConflicts(toDelete); boolean check = false; check = MessageDialog.openConfirm(getSite().getShell(), DELETE_CODE, getConfirmMessage(conflicts.size())); if (check && conflicts.size() > 0) { removeCodeFromFragments(toDelete, conflicts); } if (check) { Facade.getInstance().deleteCode(toDelete); CommonNavigator view = (CommonNavigator) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().findView(QualyzerActivator.PROJECT_EXPLORER_VIEW_ID); view.getCommonViewer().refresh(); } } }; }