/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources * the resources to copy to the clipboard * @param fileNames * file names of the resources to copy to the clipboard * @param names * string representation of all names */ private void setClipboard(final IResource[] resources, final String[] fileNames, final String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (final SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO //$NON-NLS-1$ // ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, "Problem with copy.")) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
@Override public void runWithEvent(Event event) { ISelection selection = selectionProvider.getSelection(); Collection<IProductModel> productModels = ProductSupport.toProductModels(selection); Collection<IFeatureModel> featureModels = FeatureSupport.toFeatureModels(selection); Collection<IPluginModelBase> pluginModels = PluginSupport.toPluginModels(selection); Collection<IProject> projects = new HashSet<IProject>(); addUnderlyingResources(projects, productModels); addUnderlyingResources(projects, featureModels); addUnderlyingResources(projects, pluginModels); String[] fileData = new String[projects.size()]; int i = 0; for (IProject project : projects) { fileData[i++] = project.getLocation().toOSString(); } String textData = getTextData(productModels, featureModels, pluginModels); Object[] data = { projects.toArray(new IResource[projects.size()]), textData, fileData }; Transfer[] dataTypes = { ResourceTransfer.getInstance(), TextTransfer.getInstance(), FileTransfer.getInstance() }; clipboard.setContents(data, dataTypes); }
protected void initializeEditor() { GraphicalViewer graphicalViewer = getGraphicalViewer(); graphicalViewer.addDropTargetListener(new JSSTemplateTransferDropTargetListener(graphicalViewer)); graphicalViewer.addDropTargetListener(new ReportUnitDropTargetListener(graphicalViewer)); graphicalViewer.addDropTargetListener(new ImageResourceDropTargetListener(graphicalViewer, ResourceTransfer .getInstance())); graphicalViewer.addDropTargetListener(new ImageResourceDropTargetListener(graphicalViewer, FileTransfer .getInstance())); graphicalViewer.addDropTargetListener(new ImageResourceDropTargetListener(graphicalViewer, ImageURLTransfer .getInstance())); // Load the contributed drop providers for the contributed template styles List<TemplateViewProvider> dropProviders = JaspersoftStudioPlugin.getExtensionManager().getStylesViewProvider(); for (TemplateViewProvider provider : dropProviders) { AbstractTransferDropTargetListener listener = provider.getDropListener(graphicalViewer); if (listener != null) graphicalViewer.addDropTargetListener(listener); } getEditorSite().getActionBarContributor(); }
public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); // show the shortcut bar and progress indicator, which are hidden by // default configurer.setShowPerspectiveBar(true); configurer.setShowFastViewBars(true); configurer.setShowProgressIndicator(true); // add the drag and drop support for the editor area configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance()); configurer.addEditorAreaTransfer(ResourceTransfer.getInstance()); configurer.addEditorAreaTransfer(FileTransfer.getInstance()); configurer.addEditorAreaTransfer(MarkerTransfer.getInstance()); configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter( configurer.getWindow())); hookTitleUpdateListeners(configurer); }
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources * the resources to copy to the clipboard * @param fileNames * file names of the resources to copy to the clipboard * @param names * string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(shell, "Problem Copying to Clipboard", "There was a problem when accessing the system clipboard. Retry?")) { setClipboard(resources, fileNames, names); } } }
private void addDragAdapters(StructuredViewer viewer) { int ops= DND.DROP_COPY | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; DelegatingDragAdapter dragAdapter= new DelegatingDragAdapter() { @Override public void dragStart(DragSourceEvent event) { IStructuredSelection selection= (IStructuredSelection) fSelectionProviderMediator.getSelection(); if (selection.isEmpty()) { event.doit= false; return; } super.dragStart(event); } }; dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new FileTransferDragAdapter(fSelectionProviderMediator)); viewer.addDragSupport(ops, transfers, dragAdapter); }
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources the resources to copy to the clipboard * @param fileNames file names of the resources to copy to the clipboard * @param names string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents( new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, //$NON-NLS-1$ "Problem with copy.")) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
private boolean isDroppedDataAnImage(DropTargetEvent event) { if (ResourceTransfer.getInstance().isSupportedType(event.currentDataType)){ if(event.data instanceof IResource[]){ // Dropping an image resource from inside workspace IResource imgResource = ((IResource[])event.data)[0]; return ImageUtils.hasValidFileImageExtension( imgResource.getProjectRelativePath().getFileExtension()); } } else if(FileTransfer.getInstance().isSupportedType(event.currentDataType)){ // Dropping an image resource from outside workspace if(event.data instanceof String[]){ String filepath = ((String[])event.data)[0]; if(filepath!=null){ int lastIndexOfDot = filepath.lastIndexOf("."); if(lastIndexOfDot!=-1){ String extension = filepath.substring(lastIndexOfDot+1); return ImageUtils.hasValidFileImageExtension(extension); } } } } else if(ImageURLTransfer.getInstance().isSupportedType(event.currentDataType)){ // Dropping an image dropped from a contributed view (i.e: repository view) return (event.data instanceof String); } return false; }
@Override public IStatus handleDrop(final CommonDropAdapter adapter, final DropTargetEvent event, final Object target) { if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) { final String[] files = (String[]) event.data; if (files != null && files.length > 0) { PasteAction.handlePaste(files); return Status.OK_STATUS; } } else if (ResourceTransfer.getInstance().isSupportedType(event.currentDataType)) { } return Status.CANCEL_STATUS; }
protected final IResource[] getClipboardResources(TransferData[] availableDataTypes) { Transfer transfer= ResourceTransfer.getInstance(); if (isAvailable(transfer, availableDataTypes)) { return (IResource[])getContents(fClipboard2, transfer, getShell()); } return null; }
@Override public boolean canEnable(TransferData[] availableDataTypes) { boolean resourceTransfer= isAvailable(ResourceTransfer.getInstance(), availableDataTypes); boolean javaElementTransfer= isAvailable(JavaElementTransfer.getInstance(), availableDataTypes); if (! javaElementTransfer) return canPasteSimpleProjects(availableDataTypes); if (! resourceTransfer) return canPasteJavaProjects(availableDataTypes); return canPasteJavaProjects(availableDataTypes) && canPasteSimpleProjects(availableDataTypes); }
private static Transfer[] createDataTypeArray(IResource[] resources, IJavaElement[] javaElements, String[] fileNames, TypedSource[] typedSources) { List<ByteArrayTransfer> result= new ArrayList<ByteArrayTransfer>(4); if (resources.length != 0) result.add(ResourceTransfer.getInstance()); if (javaElements.length != 0) result.add(JavaElementTransfer.getInstance()); if (fileNames.length != 0) result.add(FileTransfer.getInstance()); if (typedSources.length != 0) result.add(TypedSourceTransfer.getInstance()); result.add(TextTransfer.getInstance()); return result.toArray(new Transfer[result.size()]); }
public void start() { Assert.isLegal(!fStarted); int ops= DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; fViewer.addDragSupport(ops, transfers, fDragAdapter); fStarted= true; }
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance() }; int ops= DND.DROP_COPY | DND.DROP_LINK; JdtViewerDragAdapter dragAdapter= new JdtViewerDragAdapter(viewer); dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(viewer)); viewer.addDragSupport(ops, transfers, dragAdapter); }
private void addDragAdapters(StructuredViewer viewer) { int ops= DND.DROP_COPY | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; JdtViewerDragAdapter dragAdapter= new JdtViewerDragAdapter(viewer); dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new FileTransferDragAdapter(viewer)); viewer.addDragSupport(ops, transfers, dragAdapter); }
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources the resources to copy to the clipboard * @param fileNames file names of the resources to copy to the clipboard * @param names string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog .openQuestion( shell, WorkbenchNavigatorMessages.actions_CopyAction_msgTitle, // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, //$NON-NLS-1$ WorkbenchNavigatorMessages.actions_CopyAction_msg)) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers= new Transfer[] { ResourceTransfer.getInstance() }; int ops= DND.DROP_COPY | DND.DROP_LINK; viewer.addDragSupport(ops, transfers, new NavigatorDragAdapter(viewer)); }
/** * Configure outline viewer. */ protected void configureOutlineViewer() { final EditPartViewer viewer = getViewer(); viewer.setEditDomain(editor.getEditDomain()); viewer.setEditPartFactory(getEditPartFactory()); ContextMenuProvider provider = getMenuContentProvider(); viewer.setContextMenu(provider); viewer.addDropTargetListener(new JSSTemplateTransferDropTargetListener(viewer)); viewer.addDragSourceListener(new TemplateTransferDragSourceListener(viewer) { @Override protected Object getTemplate() { List<Object> models = new ArrayList<Object>(); Object obj = super.getTemplate(); if (obj == null) { List<?> selection = getViewer().getSelectedEditParts(); for (Object it : selection) { if (it instanceof EditPart) { Object model = ((EditPart) it).getModel(); if (model instanceof IDragable) { models.add(model); } if (model instanceof MBand){ BandTypeEnum bandType =((MBand)model).getBandType(); if (BandTypeEnum.DETAIL.equals(bandType) || BandTypeEnum.GROUP_FOOTER.equals(bandType) || BandTypeEnum.GROUP_HEADER.equals(bandType)){ models.add(model); } } } } } return models; } }); // Add images drop listeners viewer.addDropTargetListener(new ImageResourceDropTargetListener(viewer, ResourceTransfer.getInstance())); viewer.addDropTargetListener(new ImageResourceDropTargetListener(viewer, FileTransfer.getInstance())); viewer.addDropTargetListener(new ImageResourceDropTargetListener(viewer, ImageURLTransfer.getInstance())); IPageSite site = getSite(); site.registerContextMenu(provider.getId(), provider, site.getSelectionProvider()); IToolBarManager tbm = site.getActionBars().getToolBarManager(); registerToolbarAction(tbm); showPage(ID_ACTION_OUTLINE); }
/** * The <code>PasteAction</code> implementation of this <code>SelectionListenerAction</code> method enables this * action if a resource compatible with what is on the clipboard is selected. * * -Clipboard must have IResource or java.io.File -Projects can always be pasted if they are open -Workspace folder * may not be copied into itself -Files and folders may be pasted to a single selected folder in open project or * multiple selected files in the same folder */ @Override protected boolean updateSelection(final IStructuredSelection selection) { if (!super.updateSelection(selection)) { return false; } final IResource[][] clipboardData = new IResource[1][]; shell.getDisplay().syncExec(() -> { // clipboard must have resources or files final ResourceTransfer resTransfer = ResourceTransfer.getInstance(); clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer); }); final IResource[] resourceData = clipboardData[0]; final boolean isProjectRes = resourceData != null && resourceData.length > 0 && resourceData[0].getType() == IResource.PROJECT; if (isProjectRes) { for (int i = 0; i < resourceData.length; i++) { // make sure all resource data are open projects // can paste open projects regardless of selection if (resourceData[i].getType() != IResource.PROJECT || ((IProject) resourceData[i]).isOpen() == false) { return false; } } return true; } if (getSelectedNonResources().size() > 0) { return false; } final IResource targetResource = getTarget(); // targetResource is null if no valid target is selected (e.g., open project) // or selection is empty if (targetResource == null) { return false; } // can paste files and folders to a single selection (file, folder, // open project) or multiple file selection with the same parent final List<? extends IResource> selectedResources = getSelectedResources(); if (selectedResources.size() > 1) { for (final IResource resource : selectedResources) { if (resource.getType() != IResource.FILE) { return false; } if (!targetResource.equals(resource.getParent())) { return false; } } } if (resourceData != null) { // linked resources can only be pasted into projects if (isLinked(resourceData) && targetResource.getType() != IResource.PROJECT && targetResource.getType() != IResource.FOLDER) { return false; } if (targetResource.getType() == IResource.FOLDER) { // don't try to copy folder to self for (int i = 0; i < resourceData.length; i++) { if (targetResource.equals(resourceData[i])) { return false; } } } return true; } final TransferData[] transfers = clipboard.getAvailableTypes(); final FileTransfer fileTransfer = FileTransfer.getInstance(); for (int i = 0; i < transfers.length; i++) { if (fileTransfer.isSupportedType(transfers[i])) { return true; } } return false; }
@Override public boolean canEnable(TransferData[] availableTypes) { return isAvailable(ResourceTransfer.getInstance(), availableTypes) || isAvailable(JavaElementTransfer.getInstance(), availableTypes); }
@Override public boolean canEnable(TransferData[] availableTypes) { fAvailableTypes= availableTypes; return isAvailable(JavaElementTransfer.getInstance(), availableTypes) || isAvailable(ResourceTransfer.getInstance(), availableTypes); }
public Transfer getTransfer() { return ResourceTransfer.getInstance(); }
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$ } // alwaysOverwrite = false; if (aTarget == null || aDropTargetEvent.data == null) { return Status.CANCEL_STATUS; } IStatus status = null; IResource[] resources = null; TransferData currentTransfer = aDropAdapter.getCurrentTransfer(); if (LocalSelectionTransfer.getTransfer().isSupportedType( currentTransfer)) { resources = getSelectedResources(); } else if (ResourceTransfer.getInstance().isSupportedType( currentTransfer)) { resources = (IResource[]) aDropTargetEvent.data; } if (FileTransfer.getInstance().isSupportedType(currentTransfer)) { status = performFileDrop(aDropAdapter, aDropTargetEvent.data); } else if (resources != null && resources.length > 0) { if ((aDropAdapter.getCurrentOperation() == DND.DROP_COPY) || (aDropAdapter.getCurrentOperation() == DND.DROP_LINK)) { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$ } status = performResourceCopy(aDropAdapter, getShell(), resources); } else { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$ } status = performResourceMove(aDropAdapter, resources); } } openError(status); IContainer target = getActualTarget((IResource) aTarget); if (target != null && target.isAccessible()) { try { target.refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { } } return status; }
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers = new Transfer[] { ResourceTransfer.getInstance() }; int ops = DND.DROP_COPY | DND.DROP_LINK; viewer.addDragSupport(ops, transfers, new NavigatorDragAdapter(viewer)); }
@Override public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { // aTarget = getActual(aTarget); if (DEBUG) { System.out.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$ } // alwaysOverwrite = false; if (getCurrentTarget(aDropAdapter) == null || aDropTargetEvent.data == null) { return Status.CANCEL_STATUS; } IStatus status = null; IResource[] resources = null; TransferData currentTransfer = aDropAdapter.getCurrentTransfer(); if (LocalSelectionTransfer.getTransfer().isSupportedType(currentTransfer)) { resources = getSelectedResources(); } else if (ResourceTransfer.getInstance().isSupportedType(currentTransfer)) { resources = (IResource[]) aDropTargetEvent.data; } if (FileTransfer.getInstance().isSupportedType(currentTransfer)) { status = performFileDrop(aDropAdapter, aDropTargetEvent.data); } else if (resources != null && resources.length > 0) { if (aDropAdapter.getCurrentOperation() == DND.DROP_COPY) { if (DEBUG) { System.out.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$ } status = performResourceCopy(aDropAdapter, getShell(), resources); } else { if (DEBUG) { System.out.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$ } status = performResourceMove(aDropAdapter, resources); } } openError(status); IContainer target = getActualTarget((IResource) getCurrentTarget(aDropAdapter)); if (target != null && target.isAccessible()) { try { target.refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { } } return status; }