List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.ibm.research.tagging.core.ui.dialogs.OpenWaypointDialog.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { // @tag hack openwaypoint : using selectionChanged instead of getSelection... getSelection returning empty structured selection objects! IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection(); Object[] selection = structuredSelection.toArray(); if (selection.length > 0) { selectedWaypoints = new IWaypoint[selection.length]; for (int i = 0; i < selection.length; i++) selectedWaypoints[i] = (IWaypoint) selection[i]; } else {// w ww . ja v a 2 s . c o m selectedWaypoints = null; } }
From source file:com.ibm.research.tagging.core.ui.tags.TagViewListener.java
License:Open Source License
public void deleteTag(TagView view) { IStructuredSelection tagSelection = (IStructuredSelection) view.getTagTableViewer().getSelection(); boolean doIt = true; if (!MessageDialog.openQuestion(view.getSite().getShell(), "Tag View", "Are you sure you want to delete the selected tag(s)?")) doIt = false;//from www .j av a 2s .c o m if (doIt) { for (Object o : tagSelection.toArray()) { ITag tag = (ITag) o; TagCorePlugin.getDefault().getTagCore().getTagModel().removeTag(tag); } } }
From source file:com.ibm.research.tagging.core.ui.tags.TagViewListener.java
License:Open Source License
public void renameTag(TagView view) { IStructuredSelection selection = (IStructuredSelection) view.getTagTableViewer().getSelection(); if (selection.size() == 1) { ITag tag = (ITag) selection.toArray()[0]; NoWhitespaceNameValidator validator = new NoWhitespaceNameValidator(); InputDialog dialog = new InputDialog(view.getTagTableViewer().getTable().getShell(), "Rename tag", "Enter the new name for the tag:", tag.getName(), validator); if (dialog.open() == InputDialog.OK) { String newName = dialog.getValue().trim(); TagCorePlugin.getDefault().getTagCore().getTagModel().renameTag(tag, newName); }/* w w w. j av a 2 s. c o m*/ } }
From source file:com.ibm.research.tagging.core.ui.waypoints.WaypointTableSelectionChangedListener.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection(); Object[] selection = structuredSelection.toArray(); WaypointView view = TagUIPlugin.getDefault().getWaypointView(); if (view != null) { // If a single item is selected then populate the collapsable sections if (selection.length > 0) { Set<ITag> tags = new HashSet<ITag>(); for (Object selected : selection) { IWaypoint waypoint = (IWaypoint) selected; for (ITag tag : waypoint.getTags()) tags.add(tag);//from w w w . j a v a2s .co m } view.setTags(tags.toArray(new ITag[0])); if (selection.length == 1) view.setSelectedWaypoint((IWaypoint) selection[0]); else view.clearSelectedWaypoint(); } else { view.clearTags(); view.clearSelectedWaypoint(); } view.refreshSections(); } }
From source file:com.ibm.research.tagging.core.ui.waypoints.WaypointViewListener.java
License:Open Source License
public void deleteWaypoint(WaypointView view) { IStructuredSelection waypointSelection = (IStructuredSelection) view.getWaypointTableViewer() .getSelection();//from w w w . j a va 2 s .c o m boolean doIt = true; if (!MessageDialog.openQuestion(view.getSite().getShell(), "Waypoint View", "Are you sure you want to delete the selected waypoints?")) doIt = false; if (doIt) { for (Object o : waypointSelection.toArray()) { IWaypoint waypoint = (IWaypoint) o; TagCorePlugin.getDefault().getTagCore().getWaypointModel().removeWaypoint(waypoint); } } }
From source file:com.ibm.research.tagging.resource.actions.QuickTagActionDelegate.java
License:Open Source License
public void run(IAction action) { if (fSelection != null) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); QuickTagDialog dialog = new QuickTagDialog(shell, DIALOG_TITLE, null); if (dialog.open() == Window.OK) { String[] tags = dialog.getTags(); if (tags.length > 0) { IStructuredSelection structuredSelection = (IStructuredSelection) fSelection; for (Object o : structuredSelection.toArray()) { IResource resource = null; if (o instanceof IResource) { resource = (IResource) o; } else if (o instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) o; resource = (IResource) adaptable.getAdapter(IResource.class); }//from w w w .j av a2s . c om if (resource != null) { if (resource.exists()) { try { // look for an existing resource marker IMarker marker = ResourceWaypointUtil.getFirstMarker(ResourceWaypoint.MARKER_ID, resource); ResourceWaypoint waypoint = null; // an existing maker exists if (marker != null) { IWaypoint w = ResourceWaypointUtil .getWaypointFromModel(Long.toString(marker.getId())); if (w != null) waypoint = (ResourceWaypoint) w; } if (waypoint == null) waypoint = new ResourceWaypoint(resource, null, System.getProperty("user.name"), new Date()); TagCorePlugin.getDefault().getTagCore().getWaypointModel() .addWaypoint(waypoint); ResourceWaypointUtil.tag(waypoint, tags); waypoint.save(); } catch (CoreException e) { e.printStackTrace(); } } } } } } } }
From source file:com.ibm.research.tagging.resource.wizards.NewResourceWaypointWizard.java
License:Open Source License
@Override public void init(IWorkbench workbench, IStructuredSelection selection) { super.init(workbench, selection); // set defaults if we selected one resource (not multiple) if (selection != null) { Object[] o = selection.toArray(); if (o.length == 1 && o[0] instanceof IAdaptable) { IResource resource = getResource(o[0]); if (resource != null) { // look for an existing resource marker IMarker marker = ResourceWaypointUtil.getFirstMarker(ResourceWaypoint.MARKER_ID, resource); ResourceWaypoint waypoint = null; // if an existing marker exists, get the waypoint - if any - and use its data to prepopulate the wizard fields if (marker != null) { IWaypoint w = ResourceWaypointUtil.getWaypointFromModel(Long.toString(marker.getId())); if (w != null) waypoint = (ResourceWaypoint) w; }/*w w w . j ava2 s.c o m*/ if (waypoint != null) { getPage().setDefaultAuthorText(waypoint.getAuthor()); getPage().setDefaultDescriptionText(waypoint.getDescription()); getPage().setDefaultTagsText(waypoint.getTags()); } // if no existing waypoint, and if this is a project, get the project's manifest info for the waypoint description else if (resource instanceof IProject) { String bundleName = readManifestBundleName((IProject) resource); if (bundleName != null) getPage().setDefaultDescriptionText(bundleName); } } } } }
From source file:com.ibm.research.tagging.resource.wizards.NewResourceWaypointWizard.java
License:Open Source License
public boolean performFinish() { String[] tagNames = getPage().getTags(); String author = getPage().getAuthorText(), desc = getPage().getDescriptionText(); IStructuredSelection selection = getSelection(); if (selection == null) { MessageDialog.openError(getShell(), "error", "no resources selected to create waypoints with"); return false; }/*from ww w. j a va 2s. c om*/ for (Object o : selection.toArray()) { IResource resource = getResource(o); if (resource != null) { try { // look for an existing resource marker IMarker marker = ResourceWaypointUtil.getFirstMarker(ResourceWaypoint.MARKER_ID, resource); ResourceWaypoint waypoint = null; // an existing maker exists if (marker != null) { IWaypoint w = ResourceWaypointUtil.getWaypointFromModel(Long.toString(marker.getId())); if (w != null) waypoint = (ResourceWaypoint) w; } if (waypoint == null) waypoint = new ResourceWaypoint(resource, desc, author, new Date()); else { // update the description and author at least waypoint.setAuthor(author); waypoint.setDescription(desc); } TagCorePlugin.getDefault().getTagCore().getWaypointModel().addWaypoint(waypoint); ResourceWaypointUtil.tag(waypoint, tagNames); waypoint.save(); } catch (CoreException e) { ResourceWaypointPlugin.log("exception while trying to waypoint resource=" + resource, e); } } } return true; }
From source file:com.ibm.research.tours.actions.TourElementActionDelegate.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; fSelectedElements = new ArrayList<ITourElement>(); if (!structuredSelection.isEmpty()) { Object[] selectionArray = structuredSelection.toArray(); for (Object o : selectionArray) { if (o instanceof ITourElement) fSelectedElements.add((ITourElement) o); }/*from w w w . j a v a2 s. com*/ } }
From source file:com.ibm.research.tours.content.actions.PickFileActionDelegate.java
License:Open Source License
public void run(IAction action) { IStructuredSelection structuredSelection = (IStructuredSelection) fSelection; Object[] selection = structuredSelection.toArray(); Object file = null;//from w ww. ja v a 2 s . co m if (selection[0] instanceof IFileEditorInput) { IFileEditorInput input = (IFileEditorInput) selection[0]; file = input.getFile(); } else if (selection[0] instanceof IClassFileEditorInput) { IClassFileEditorInput input = (IClassFileEditorInput) selection[0]; file = input.getClassFile(); } if (file != null) ToursContentPlugin.getDefault().getFileClipBoard().put(file); }