Skip to content

Commit

Permalink
TEIIDDES-1703: Make it obvious what the delete action will cover
Browse files Browse the repository at this point in the history
* Places a tree viewer on the 'Are you sure?' dialog box displaying all the
  resources and dependencies that will be deleted by the delete refactoring

* Makes it plain to the user that these resources will be deleted if they
  click ok but can deselect them if they click preview.
  • Loading branch information
Paul Richardson committed May 7, 2013
1 parent b4d1dec commit eabee81
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,8 @@ RenameRefactoring.renameResourcePage = Enter the new name for the resource
RenameRefactoring.nameLabel = New na&me:

DeleteRefactoring.title = Delete Resource(s)
DeleteRefactoring.deleteResourceLabel = Resources to be deleted (VDBs will be re-synchronized)
DeleteRefactoring.previewOrOKLabel = Click Preview to edit the list of resources or OK to delete all listed
DeleteRefactoring.initialConditions = Checking Pre-conditions of delete ...
DeleteRefactoring.finalConditions = Checking conditions of delete ...
DeleteRefactoring.creatingChange = Creating changes for delete ...
Expand All @@ -1606,10 +1608,10 @@ DeleteRefactoring.warningOutOfSync = The resource {0} is out of sync with the fi
DeleteRefactoring.deleteDescriptorDescription = Delete of resource(s)
DeleteRefactoring.deleteDescriptorComment = Delete of resource(s)
DeleteRefactoring.deleteResourcesConfigurationPage = Set the options for the delete of the resource(s)
DeleteRefactoring.labelMulti = Are you sure you want to delete the {0} selected resources AND their dependents?
DeleteRefactoring.labelSingle = Are you sure you want to delete ''{0}'' AND its dependents?
DeleteRefactoring.labelMultiLinked = Are you sure you want to delete these {0} resources AND their dependents?\n\nSelection contains linked resources.\nOnly the workspace links will be deleted. Link targets will remain unchanged.
DeleteRefactoring.labelSingleLinked = Are you sure you want to delete linked resource ''{0}' AND its dependents'?\n\nOnly the workspace link will be deleted. Link target will remain unchanged.
DeleteRefactoring.labelMulti = Are you sure you want to delete the {0} selected resources and their dependents?
DeleteRefactoring.labelSingle = Are you sure you want to delete ''{0}'' and its dependents?
DeleteRefactoring.labelMultiLinked = Are you sure you want to delete these {0} resources and their dependents?\n\nSelection contains linked resources.\nOnly the workspace links will be deleted. Link targets will remain unchanged.
DeleteRefactoring.labelSingleLinked = Are you sure you want to delete linked resource ''{0}' and its dependents'?\n\nOnly the workspace link will be deleted. Link target will remain unchanged.
DeleteRefactoring.labelMultiProjects = Are you sure you want to remove these {0} projects from the workspace?
DeleteRefactoring.labelSingleProject = Are you sure you want to remove project ''{0}'' from the workspace?
DeleteRefactoring.projectDeleteContents = &Delete project contents on disk (cannot be undone)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
*/
package org.teiid.designer.ui.refactor.delete;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.LayoutConstants;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
Expand All @@ -24,10 +32,15 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.designer.core.refactor.RelatedResourceFinder.Relationship;
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.explorer.ModelExplorerLabelProvider;
import org.teiid.designer.ui.refactor.AbstractResourcesRefactoring;
import org.teiid.designer.ui.refactor.RefactorResourcesUtils;
import org.teiid.designer.ui.refactor.RefactorResourcesUtils.AbstractResourceCallback;

/**
*
Expand Down Expand Up @@ -127,49 +140,173 @@ public void createControl(Composite parent) {
supportArea.setLayout(gridLayout);

if (onlyProjects) {
deleteContentsButton = new Button(supportArea, SWT.CHECK);
deleteContentsButton.setFont(composite.getFont());
deleteContentsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
deleteContentsButton.setText(RefactorResourcesUtils.getString("DeleteRefactoring.projectDeleteContents")); //$NON-NLS-1$
deleteContentsButton.setFocus();
deleteContentsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getRefactoring().setDeleteContents(deleteContentsButton.getSelection());
}
});

Label projectLocationsLabel = new Label(supportArea, SWT.NONE);
GridData labelData = new GridData(SWT.FILL, SWT.FILL, true, false);
labelData.verticalIndent = 5;
projectLocationsLabel.setLayoutData(labelData);
projectLocationsLabel.setText(resources.size() == 1 ?
RefactorResourcesUtils.getString("DeleteRefactoring.projectLocation") : //$NON-NLS-1$
RefactorResourcesUtils.getString("DeleteRefactoring.project_locations")); //$NON-NLS-1$

int style = SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL;
if (resources.size() != 1) style |= SWT.BORDER;
StyledText projectLocationsList = new StyledText(supportArea, style);
projectLocationsList.setAlwaysShowScrollBars(false);
labelData.horizontalIndent = projectLocationsList.getLeftMargin();
gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
projectLocationsList.setLayoutData(gridData);
projectLocationsList.setBackground(projectLocationsList.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

StringBuffer buf = new StringBuffer();
for (IResource resource : resources) {
String location = resource.getFullPath().toOSString();
if (buf.length() > 0)
buf.append('\n');

buf.append(location);
}
projectLocationsList.setText(buf.toString());
gridData.heightHint = Math.min(convertHeightInCharsToPixels(5),
projectLocationsList.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
createProjectInfoArea(supportArea, resources);
} else {
createResourceInfoArea(supportArea, resources);
}

setControl(composite);
}

/**
* @param composite
* @param resources
* @param parent
*/
private void createProjectInfoArea(Composite parent, List<IResource> resources) {
GridData gridData;

deleteContentsButton = new Button(parent, SWT.CHECK);
deleteContentsButton.setFont(parent.getFont());
deleteContentsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
deleteContentsButton.setText(RefactorResourcesUtils.getString("DeleteRefactoring.projectDeleteContents")); //$NON-NLS-1$
deleteContentsButton.setFocus();
deleteContentsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getRefactoring().setDeleteContents(deleteContentsButton.getSelection());
}
});

Label projectLocationsLabel = new Label(parent, SWT.NONE);
GridData labelData = new GridData(SWT.FILL, SWT.FILL, true, false);
labelData.verticalIndent = 5;
projectLocationsLabel.setLayoutData(labelData);
projectLocationsLabel.setText(resources.size() == 1 ?
RefactorResourcesUtils.getString("DeleteRefactoring.projectLocation") : //$NON-NLS-1$
RefactorResourcesUtils.getString("DeleteRefactoring.project_locations")); //$NON-NLS-1$

int style = SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL;
if (resources.size() != 1) style |= SWT.BORDER;
StyledText projectLocationsList = new StyledText(parent, style);
projectLocationsList.setAlwaysShowScrollBars(false);
labelData.horizontalIndent = projectLocationsList.getLeftMargin();
gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
projectLocationsList.setLayoutData(gridData);
projectLocationsList.setBackground(projectLocationsList.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

StringBuffer buf = new StringBuffer();
for (IResource resource : resources) {
String location = resource.getFullPath().toOSString();
if (buf.length() > 0)
buf.append('\n');

buf.append(location);
}
projectLocationsList.setText(buf.toString());
gridData.heightHint = Math.min(convertHeightInCharsToPixels(5),
projectLocationsList.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
}

/**
* @param supportArea
* @param resources
*/
private void createResourceInfoArea(Composite parent, List<IResource> resources) {
Group group = WidgetFactory.createGroup(parent,
RefactorResourcesUtils.getString("DeleteRefactoring.deleteResourceLabel"), //$NON-NLS-1$
GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL |
GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);

TreeViewer viewer = new TreeViewer(group, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());

viewer.setContentProvider(new ResourcesContentProvider());
viewer.setLabelProvider(new ModelExplorerLabelProvider());
viewer.setAutoExpandLevel(5);
viewer.setInput(resources);

Label detailLabel = new Label(parent, SWT.NONE);
detailLabel.setText(RefactorResourcesUtils.getString("DeleteRefactoring.previewOrOKLabel")); //$NON-NLS-1$
}
}

private static class ResourcesContentProvider implements ITreeContentProvider {

private Set<IResource> rootCollection = new HashSet<IResource>();

@Override
public Object[] getChildren(Object parentElement) {
if (parentElement == null)
return new Object[0];

if (parentElement instanceof List) {
return ((List) parentElement).toArray();
}
else if (rootCollection.contains(parentElement)) {
RefactoringStatus status = new RefactoringStatus();
IndexResourceCallback callback = new IndexResourceCallback();
RefactorResourcesUtils.calculateRelatedResources((IResource) parentElement, status, callback, Relationship.DEPENDENT);
RefactorResourcesUtils.calculateRelatedVdbResources((IResource) parentElement, status, callback);

return callback.getResources().toArray();
}

return new Object[0];
}

@Override
public Object getParent(Object element) {
if (element instanceof IResource) {
return ((IResource) element).getParent();
}

return null;
}

@Override
public boolean hasChildren(Object element) {
if (element instanceof IContainer)
return true;

if (rootCollection.contains(element))
return true;

return false;
}

@Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}

@Override
public void dispose() {
rootCollection.clear();
}

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
rootCollection.clear();
if (newInput instanceof List) {
for (Object element : (List) newInput) {
if (element instanceof IResource)
rootCollection.add((IResource) element);
}
}
}
}

private static class IndexResourceCallback extends AbstractResourceCallback {

private Set<IResource> resources = new HashSet<IResource>();

/**
* @return the resources
*/
public Set<IResource> getResources() {
return this.resources;
}

@Override
public void indexFile(IResource resource, IFile relatedFile, RefactoringStatus status) throws Exception {
resources.add(relatedFile);
RefactorResourcesUtils.calculateRelatedVdbResources(relatedFile, status, this);
}

@Override
public void indexVdb(IResource resource, IFile vdbFile, RefactoringStatus status) {
resources.add(vdbFile);
}
};
}

0 comments on commit eabee81

Please sign in to comment.