void checkLocationDeleted(final IProject project) throws CoreException { if (!project.exists()) { return; } final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI()); if (!location.exists()) { final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage, project.getName(), location.toString()); final MessageDialog dialog = new MessageDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RefreshAction_dialogTitle, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) { @Override protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; WorkbenchHelper.run(() -> dialog.open()); // Do the deletion back in the operation thread if (dialog.getReturnCode() == 0) { // yes was chosen project.delete(true, true, null); } } }
/** * Checks whether the given project's location has been deleted. If so, prompts the user with whether to delete the * project or not. */ void checkLocationDeleted(final IProject project) throws CoreException { if (!project.exists()) { return; } final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI()); if (!location.exists()) { final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage, project.getName(), location.toString()); final MessageDialog dialog = new MessageDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RefreshAction_dialogTitle, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) { @Override protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; WorkbenchHelper.run(() -> dialog.open()); // Do the deletion back in the operation thread if (dialog.getReturnCode() == 0) { // yes was chosen project.delete(true, true, null); } } }
public IStatus validate(Object[] selection) { int nSelected = selection.length; String pluginId = IDEWorkbenchPlugin.IDE_WORKBENCH; if (nSelected == 0 || (nSelected > 1 && multiSelect == false)) { return new Status(IStatus.ERROR, pluginId, IStatus.ERROR, IDEResourceInfoUtils.EMPTY_STRING, null); } for (int i = 0; i < selection.length; i++) { Object curr = selection[i]; if (curr instanceof IFileStore) { IFileStore file = (IFileStore) curr; if (acceptFolders == false && file.fetchInfo().isDirectory()) { return new Status(IStatus.ERROR, pluginId, IStatus.ERROR, IDEResourceInfoUtils.EMPTY_STRING, null); } } } return Status.OK_STATUS; }
public Object[] getChildren(Object parentElement) { if (parentElement instanceof IFileStore) { IFileStore[] children = IDEResourceInfoUtils.listFileStores( (IFileStore) parentElement, fileFilter, new NullProgressMonitor()); if (children != null) { return children; } } return EMPTY; }
/** * Checks whether the resources with the given names exist. * * @param resources * IResources to checl * @return Multi status with one error message for each missing file. */ IStatus checkExist(IResource[] resources) { MultiStatus multiStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, getProblemsMessage(), null); for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; if (resource != null) { URI location = resource.getLocationURI(); String message = null; if (location != null) { IFileInfo info = IDEResourceInfoUtils.getFileInfo(location); if (info == null || info.exists() == false) { if (resource.isLinked()) { message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_missingLinkTarget, resource.getName()); } else { message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceDeleted, resource.getName()); } } } if (message != null) { IStatus status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, message, null); multiStatus.add(status); } } } return multiStatus; }
/** * Build the collection of fileStores that map to fileNames. If any of them * cannot be found then match then return null. * * @param fileNames * @return IFileStore[] */ private IFileStore[] buildFileStores(final String[] fileNames) { IFileStore[] stores = new IFileStore[fileNames.length]; for (int i = 0; i < fileNames.length; i++) { IFileStore store = IDEResourceInfoUtils.getFileStore(fileNames[i]); if (store == null) { reportFileInfoNotFound(fileNames[i]); return null; } stores[i] = store; } return stores; }
/** * Checks whether the destination is valid for copying the source files. * <p> * Note this method is for internal use only. It is not API. * </p> * * @param destination * the destination container * @param sourceNames * the source file names * @return an error message, or <code>null</code> if the path is valid */ public String validateImportDestination(IContainer destination, String[] sourceNames) { IFileStore[] stores = new IFileStore[sourceNames.length]; for (int i = 0; i < sourceNames.length; i++) { IFileStore store = IDEResourceInfoUtils.getFileStore(sourceNames[i]); if (store == null) { return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_infoNotFound, sourceNames[i]); } stores[i] = store; } return validateImportDestinationInternal(destination, stores); }
/** * Create the area for user entry. * * @param composite * @param defaultEnabled */ private void createUserEntryArea(Composite composite, boolean defaultEnabled) { // location label locationLabel = new Label(composite, SWT.NONE); locationLabel.setText(IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationLabel); // project location entry field locationPathField = new Text(composite, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = SIZING_TEXT_FIELD_WIDTH; data.horizontalSpan = 2; locationPathField.setLayoutData(data); // browse button browseButton = new Button(composite, SWT.PUSH); browseButton.setText(BROWSE_LABEL); browseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { handleLocationBrowseButtonPressed(); } }); createFileSystemSelection(composite); if (defaultEnabled) { locationPathField.setText(TextProcessor.process(getDefaultPathDisplayString())); } else { if (existingProject == null) { locationPathField.setText(IDEResourceInfoUtils.EMPTY_STRING); } else { locationPathField.setText(TextProcessor.process(existingProject.getLocation().toOSString())); } } locationPathField.addModifyListener(new ModifyListener() { /* * (non-Javadoc) * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) */ public void modifyText(ModifyEvent e) { errorReporter.reportError(checkValidLocation(), false); } }); }
/** * Open an appropriate directory browser */ private void handleLocationBrowseButtonPressed() { String selectedDirectory = null; String dirName = getPathFromLocationField(); if (!dirName.equals(IDEResourceInfoUtils.EMPTY_STRING)) { IFileInfo info; info = IDEResourceInfoUtils.getFileInfo(dirName); if (info == null || !(info.exists())) dirName = IDEResourceInfoUtils.EMPTY_STRING; } else { String value = getDialogSettings().get(SAVED_LOCATION_ATTR); if (value != null) { dirName = value; } } FileSystemConfiguration config = getSelectedConfiguration(); if (config == null || config.equals(FileSystemSupportRegistry.getInstance().getDefaultConfiguration())) { DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell(), SWT.SHEET); dialog.setMessage(IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel); dialog.setFilterPath(dirName); selectedDirectory = dialog.open(); } else { URI uri = getSelectedConfiguration().getContributor().browseFileSystem(dirName, browseButton.getShell()); if (uri != null) selectedDirectory = uri.toString(); } if (selectedDirectory != null) { updateLocationField(selectedDirectory); getDialogSettings().put(SAVED_LOCATION_ATTR, selectedDirectory); } }
/** * Check if the user wishes to overwrite the supplied resource or all * resources. * * @param source * the source resource * @param destination * the resource to be overwritten * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, * IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating * whether the current resource or all resources can be overwritten, * or if the operation should be canceled. */ private int checkOverwrite(final IResource source, final IResource destination) { final int[] result = new int[1]; // Dialogs need to be created and opened in the UI thread Runnable query = new Runnable() { @Override public void run() { String message; int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID }; String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; if (destination.getType() == IResource.FOLDER) { if (homogenousResources(source, destination)) { message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion, destination.getFullPath().makeRelative()); } else { if (destination.isLinked()) { message = NLS.bind( IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion, destination.getFullPath().makeRelative()); } else { message = NLS.bind( IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion, destination.getFullPath().makeRelative()); } resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID }; labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; } } else { String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination), IDEResourceInfoUtils.getDateStringValue(destination), IDEResourceInfoUtils.getLocationText(source), IDEResourceInfoUtils.getDateStringValue(source) }; message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion, bindings); } MessageDialog dialog = new MessageDialog(messageShell, IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message, MessageDialog.QUESTION, labels, 0); dialog.open(); if (dialog.getReturnCode() == SWT.DEFAULT) { // A window close returns SWT.DEFAULT, which has to be // mapped to a cancel result[0] = IDialogConstants.CANCEL_ID; } else { result[0] = resultId[dialog.getReturnCode()]; } } }; messageShell.getDisplay().syncExec(query); return result[0]; }