1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 133881 - Make refreshing after building optional

Add Refresh Policy Tab to C/C++ Build properties page - Work in progress.
This commit is contained in:
Vivian Kong 2011-04-20 16:04:38 +00:00
parent 065edefb78
commit 096a053e12
12 changed files with 1197 additions and 17 deletions

View file

@ -232,6 +232,13 @@
helpId="cdt_u_prop_build"
parent="org.eclipse.cdt.managedbuilder.ui.properties.Page_head_build"
weight="050"/>
<tab
class="org.eclipse.cdt.managedbuilder.ui.properties.RefreshPolicyTab"
helpId="cdt_u_prop_build"
icon="icons/elcl16/refresh_nav.gif"
name="%Refresh.policy"
parent="org.eclipse.cdt.managedbuilder.ui.properties.Page_head_build"
weight="050"/>
<tab
class="org.eclipse.cdt.managedbuilder.ui.properties.CPropertyVarsTab"
name="(Single) CDT Vars (macros)"

View file

@ -210,20 +210,18 @@ public class Messages extends NLS {
public static String PropertyPageDefsTab_8;
public static String PropertyPageDefsTab_9;
public static String PropertyPageDefsTab_showIncludeFileTab;
public static String RefreshPolicyExceptionDialog_addButtonLabel;
public static String RefreshPolicyExceptionDialog_addDialogLabel;
public static String RefreshPolicyExceptionDialog_contentTypeDropdownLabel;
public static String RefreshPolicyExceptionDialog_deleteButtonLabel;
public static String RefreshPolicyExceptionDialog_editDialogLabel;
public static String RefreshPolicyExceptionDialog_exceptionPropertiesGroupLabel;
public static String RefreshPolicyExceptionDialog_exceptionTypeContentType;
public static String RefreshPolicyExceptionDialog_exceptionTypeDropdownLabel;
public static String RefreshPolicyExceptionDialog_exceptionTypeResourceNamePattern;
public static String RefreshPolicyExceptionDialog_exceptionTypeResources;
public static String RefreshPolicyExceptionDialog_patternsGroupLabel;
public static String RefreshPolicyTab_addExceptionButtonLabel;
public static String RefreshPolicyTab_addResourceButtonLabel;
public static String RefreshPolicyTab_addResourceDialogDescription;
public static String RefreshPolicyTab_addResourceDialogTitle;
public static String RefreshPolicyTab_deleteButtonLabel;
public static String RefreshPolicyTab_deleteConfirmationDialog_question_exception;
public static String RefreshPolicyTab_deleteConfirmationDialog_question_resource;
public static String RefreshPolicyTab_deleteConfirmationDialog_title;
public static String RefreshPolicyTab_editButtonLabel;
public static String RefreshPolicyTab_exceptionsLabel;
public static String RefreshPolicyTab_resourcesGroupLabel;
@ -277,6 +275,7 @@ public class Messages extends NLS {
public static String ToolSettingsTab_0;
public static String WizardDefaultsTab_0;
public static String WizardDefaultsTab_1;
public static String RefreshPolicyTab_resourcesTreeLabel;
static {
// Initialize resource bundle.

View file

@ -199,24 +199,23 @@ NewBuildMacroDialog_label_title_edit=Edit Existing Build Variable
NewBuildMacroDialog_label_list_title=Value of Build Variable
# ----------- Refresh Policy Tab and Exception Dialog -----------
RefreshPolicyExceptionDialog_addButtonLabel=Add...
RefreshPolicyExceptionDialog_addDialogLabel=Add Exception
RefreshPolicyExceptionDialog_contentTypeDropdownLabel=Content Type:
RefreshPolicyExceptionDialog_deleteButtonLabel=Delete
RefreshPolicyExceptionDialog_editDialogLabel=Edit Exception
RefreshPolicyExceptionDialog_exceptionPropertiesGroupLabel=Exception Properties
RefreshPolicyExceptionDialog_exceptionTypeContentType=Content Type
RefreshPolicyExceptionDialog_exceptionTypeDropdownLabel=Exception Type:
RefreshPolicyExceptionDialog_exceptionTypeResourceNamePattern=Resource Name Pattern
RefreshPolicyExceptionDialog_exceptionTypeResources=Resources
RefreshPolicyExceptionDialog_patternsGroupLabel=Patterns
RefreshPolicyTab_addExceptionButtonLabel=Add Exception...
RefreshPolicyTab_addResourceButtonLabel=Add Resource...
RefreshPolicyTab_addResourceDialogDescription=Select a resource to refresh:
RefreshPolicyTab_addResourceDialogTitle=Resource Selection
RefreshPolicyTab_deleteButtonLabel=Delete...
RefreshPolicyTab_deleteConfirmationDialog_question_exception=You are removing an exception that has nested exceptions. Removing this exception will remove all nested exceptions. Do you want to continue?
RefreshPolicyTab_deleteConfirmationDialog_question_resource=You are removing a resource that has exceptions. Removing this resource will also remove all associated exceptions. Do you want to continue?
RefreshPolicyTab_deleteConfirmationDialog_title=Delete
RefreshPolicyTab_editButtonLabel=Edit...
RefreshPolicyTab_exceptionsLabel=Exceptions
RefreshPolicyTab_resourcesGroupLabel=Resources
RefreshPolicyTab_tabLabel=The following resources will be refreshed after the project is built:
RefreshPolicyTab_resourcesTreeLabel=Resources that will be refreshed after the project is built
# ----------- Resource Custom Build Step Block -----------
ResourceCustomBuildStepBlock_label_applicability=Custom Build Step Applicability

View file

@ -0,0 +1,171 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;
import java.util.Iterator;
import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
import org.eclipse.cdt.ui.resources.RefreshExclusionContributionManager;
import org.eclipse.cdt.ui.resources.RefreshExclusionContributor;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
*
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
*
* @author vkong
* @since 8.0
*
*/
public class RefreshPolicyExceptionDialog extends Dialog {
private Combo exceptionTypeCombo;
private Group exceptionPropertiesGroup;
private IResource fResourceRoot = null;
private RefreshExclusion fExclusionRoot = null;
private RefreshExclusion fNewExclusion = null;
private RefreshExclusionContributionManager fContrManager;
private boolean fAddException = true;
//should only be used by the Add Exception dialog
private java.util.List<RefreshExclusionContributor> fExclusionContributors;
private RefreshPolicyExceptionDialog(Shell parent, boolean addException){
super(parent);
setShellStyle(getShellStyle());
fContrManager = RefreshExclusionContributionManager.getInstance();
fAddException = addException;
fExclusionContributors = fContrManager.getContributors();
}
public RefreshPolicyExceptionDialog(Shell parent, IResource resource, java.util.List<RefreshExclusion> exclusions, boolean addException) {
this(parent, addException);
//this is only called when an user is adding a RefreshException to a given resource
fResourceRoot = resource;
}
public RefreshPolicyExceptionDialog(Shell parent, RefreshExclusion exclusion, boolean addException) {
this(parent, addException);
fExclusionRoot = exclusion;
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
if (fAddException)
newShell.setText(Messages.RefreshPolicyExceptionDialog_addDialogLabel);
else
newShell.setText(Messages.RefreshPolicyExceptionDialog_editDialogLabel);
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
final Composite comp = (Composite) super.createDialogArea(parent);
comp.setLayout(new GridLayout(2, false));
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
Label exceptionType = new Label(comp, SWT.NONE);
exceptionType.setText(Messages.RefreshPolicyExceptionDialog_exceptionTypeDropdownLabel);
exceptionTypeCombo = new Combo(comp, SWT.READ_ONLY);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.grabExcessHorizontalSpace = true;
exceptionTypeCombo.setLayoutData(gridData);
if (fAddException) {
Iterator<RefreshExclusionContributor> iterator = fExclusionContributors.iterator();
while (iterator.hasNext()) {
RefreshExclusionContributor contributor = iterator.next();
exceptionTypeCombo.add(contributor.getName());
}
} else {
exceptionTypeCombo.add(fContrManager.getContributor(fExclusionRoot.getContributorId()).getName());
}
exceptionTypeCombo.select(0);
exceptionTypeCombo.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (exceptionPropertiesGroup != null)
exceptionPropertiesGroup.dispose();
generateExceptionPropertiesGroup(comp, exceptionTypeCombo.getSelectionIndex());
comp.layout();
}
});
generateExceptionPropertiesGroup(comp, exceptionTypeCombo.getSelectionIndex());
return comp;
}
private void generateExceptionPropertiesGroup(Composite parent, int selectionIndex) {
exceptionPropertiesGroup = new Group(parent, SWT.NONE);
exceptionPropertiesGroup.setText(Messages.RefreshPolicyExceptionDialog_exceptionPropertiesGroupLabel);
exceptionPropertiesGroup.setLayout(new GridLayout(3, false));
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gd.verticalAlignment = GridData.FILL;
gd.horizontalSpan = 2;
exceptionPropertiesGroup.setLayoutData(gd);
if (fAddException) {
if (fNewExclusion == null || fNewExclusion.getContributorId() != fExclusionContributors.get(selectionIndex).getID()){
fNewExclusion = fExclusionContributors.get(selectionIndex).createExclusion();
}
if (fResourceRoot != null) {
fNewExclusion.setParentResource(fResourceRoot);
} else {
fNewExclusion.setParentExclusion(fExclusionRoot);
}
fExclusionContributors.get(selectionIndex).createProperiesUI(exceptionPropertiesGroup, fNewExclusion);
} else { //edit an exception
fContrManager.getContributor(fExclusionRoot.getContributorId()).createProperiesUI(exceptionPropertiesGroup, fExclusionRoot);
}
}
public RefreshExclusion getResult() {
if (fAddException)
return fNewExclusion;
return fExclusionRoot;
}
}

View file

@ -0,0 +1,591 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.resources.ExclusionInstance;
import org.eclipse.cdt.core.resources.ExclusionType;
import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
import org.eclipse.cdt.ui.CDTSharedImages;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
/**
*
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
*
* @author vkong
* @since 8.0
*/
public class RefreshPolicyTab extends AbstractCPropertyTab {
private final Image IMG_FOLDER = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_FOLDER);
private final Image IMG_FILE = ManagedBuilderUIImages.get(ManagedBuilderUIImages.IMG_FILE_OBJ);
private final Image IMG_RESOURCE = ManagedBuilderUIImages.get(ManagedBuilderUIImages.IMG_FILE_FOLDER_OBJ);
private final Image IMG_EXCEPTION = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_REFACTORING_ERROR);
private final static int IDX_ADD_RESOURCE = 0;
private final static int IDX_ADD_EXCEPTION = 1;
private final static int IDX_EDIT = 2;
private final static int IDX_DELETE = 3;
private TreeViewer fTree;
private RefreshScopeManager fManager;
private IProject fProject;
private ArrayList<_Entry> fSrc;
private List<IResource> fResourcesToRefresh;
private HashMap<IResource, List<RefreshExclusion>> fResourceToExclusionsMap = new HashMap<IResource, List<RefreshExclusion>>();
public RefreshPolicyTab() {
fManager = RefreshScopeManager.getInstance();
}
private void loadInfo() {
fResourcesToRefresh = fManager.getResourcesToRefresh(fProject);
if (fResourcesToRefresh != null) {
Iterator<IResource> iterator = fResourcesToRefresh.iterator();
while (iterator.hasNext()) {
IResource resource = iterator.next();
fResourceToExclusionsMap.put(resource, fManager.getExclusions(resource));
}
}
}
private List<RefreshExclusion> getExclusions(IResource resource) {
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
if(exclusions == null) {
exclusions = new LinkedList<RefreshExclusion>();
fResourceToExclusionsMap.put(resource, exclusions);
}
return fResourceToExclusionsMap.get(resource);
}
/**
* Wrapper for IResource/RefreshExclusion
*/
class _Entry {
//if this is not a resource to refresh, resourceToRefresh will be null
IResource resourceToRefresh = null;
//if this is not a refresh exclusion, exclusion will be null
RefreshExclusion exclusion = null;
//if this is a refresh exclusion, parent is the Exceptions node this is a child of
_Exception_Node parent = null;
// exceptions_node is the Exceptions node under this Entry, there should be a exceptions_node if this resource/refresh exclusion has nested exclusions
_Exception_Node exceptions_node = null;
// if this is a refresh exclusion, exclusion_instances is a list of exclusion instances associated with this exclusion
List<_Exclusion_Instance> exclusion_instances = new ArrayList<_Exclusion_Instance>();
_Entry(IResource _ent) {
resourceToRefresh = _ent;
if (getExclusions(resourceToRefresh) != null && getExclusions(resourceToRefresh).size() > 0)
exceptions_node = new _Exception_Node(this);
}
_Entry(RefreshExclusion _ent, _Exception_Node parent) {
exclusion = _ent;
this.parent = parent;
if (exclusion.getNestedExclusions() != null && exclusion.getNestedExclusions().size() > 0) {
exceptions_node = new _Exception_Node(this);
}
if (exclusion.getExclusionInstances() != null && exclusion.getExclusionInstances().size() > 0) {
Iterator<ExclusionInstance> iterator = exclusion.getExclusionInstances().iterator();
while (iterator.hasNext()) {
exclusion_instances.add(new _Exclusion_Instance(iterator.next(), this));
}
}
}
@Override
public String toString() {
if (isExclusion())
return exclusion.getName();
return resourceToRefresh.getFullPath().makeRelative().toString();
}
public Object[] getChildren() {
if (isExclusion()) {
List children = new ArrayList(exclusion_instances);
if (exceptions_node != null)
children.add(exceptions_node);
return children.toArray();
}
if (exceptions_node != null)
return new Object[] {exceptions_node};
return null;
}
public boolean isExclusion() {
return parent != null;
}
public void addException(RefreshExclusion exclusion) {
if (exceptions_node == null) {
exceptions_node = new _Exception_Node(this);
}
exceptions_node.addException(exclusion);
}
public void updateException(RefreshExclusion exclusion) {
List<ExclusionInstance> exclusionInstancesToAdd = exclusion.getExclusionInstances();
Iterator<ExclusionInstance> iterator = exclusionInstancesToAdd.iterator();
exclusion_instances.clear();
// List<ExclusionInstance> exclusionInstancesToRemove = this.exclusion.getExclusionInstances();
// for (int i = 0; i < exclusionInstancesToRemove.size(); i++) {
// this.exclusion.removeExclusionInstance(exclusionInstancesToRemove.get(i));
// }
while (iterator.hasNext()) {
ExclusionInstance instanceToAdd = iterator.next();
exclusion_instances.add(new _Exclusion_Instance(instanceToAdd, this));
// this.exclusion.addExclusionInstance(instanceToAdd);
}
}
public void remove() {
if (isExclusion()) {
RefreshExclusion exclusionToRemove = exclusion;
_Entry parentEntry = parent.parent;
if (parentEntry.isExclusion()) {
parentEntry.exclusion.removeNestedExclusion(exclusionToRemove);
} else {
List<RefreshExclusion> exceptions = getExclusions(parentEntry.resourceToRefresh);
exceptions.remove(exclusionToRemove);
}
//update tree
if (parent.exceptions.size() > 1) {
parent.exceptions.remove(this);
} else {
parentEntry.exceptions_node = null;
}
} else { //this is a resource to refresh
fResourceToExclusionsMap.remove(resourceToRefresh);
fResourcesToRefresh.remove(resourceToRefresh);
fSrc.remove(this);
}
}
}
class _Exception_Node {
_Entry parent; //can be IResource or RefreshExclusion - must not be null
//list of refresh exclusions under this Exceptions node
List <_Entry> exceptions = new ArrayList<_Entry>();
_Exception_Node(_Entry ent) {
parent = ent;
Iterator<RefreshExclusion> iterator = null;
if (parent.isExclusion()) {
if (parent.exclusion.getNestedExclusions() != null)
iterator = parent.exclusion.getNestedExclusions().iterator();
} else {
if (getExclusions(parent.resourceToRefresh) != null)
iterator = getExclusions(parent.resourceToRefresh).iterator();
}
if (iterator != null) {
while (iterator.hasNext()) {
exceptions.add(new _Entry(iterator.next(), this));
}
}
}
public void addException(RefreshExclusion exclusion) {
exceptions.add(new _Entry(exclusion, this));
if (parent.isExclusion()) {
parent.exclusion.addNestedExclusion(exclusion);
} else {
List<RefreshExclusion> exclusions = getExclusions(parent.resourceToRefresh);
if (exclusions == null) {
exclusions = new LinkedList<RefreshExclusion>();
fResourceToExclusionsMap.put(parent.resourceToRefresh, exclusions);
}
exclusions.add(exclusion);
}
}
public Object[] getChildren() {
return exceptions.toArray();
}
@Override
public String toString() {
return Messages.RefreshPolicyTab_exceptionsLabel;
}
}
/**
* Wrapper for ExclusionInstance
*/
class _Exclusion_Instance {
_Entry parent; //the parent refresh exclusion
ExclusionInstance instance = null;
_Exclusion_Instance(ExclusionInstance instance, _Entry parent) {
this.parent = parent;
this.instance = instance;
}
public Object[] getChildren() {
return null;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return instance.getDisplayString();
}
public void remove() {
parent.exclusion.removeExclusionInstance(instance);
parent.exclusion_instances.remove(this);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.newui.AbstractCPropertyTab#createControls(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createControls(Composite parent) {
super.createControls(parent);
fProject = page.getProject();
loadInfo();
initButtons(new String[] {
Messages.RefreshPolicyTab_addResourceButtonLabel,
Messages.RefreshPolicyTab_addExceptionButtonLabel,
Messages.RefreshPolicyTab_editButtonLabel,
Messages.RefreshPolicyTab_deleteButtonLabel}, 120);
usercomp.setLayout(new GridLayout(1, false));
Label topLabel = new Label(usercomp, SWT.NONE);
topLabel.setText(Messages.RefreshPolicyTab_tabLabel);
Group g1 = setupGroup(usercomp, Messages.RefreshPolicyTab_resourcesGroupLabel, 2, GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
fSrc = new ArrayList<_Entry>();
generateTreeContent(fProject);
fTree = new TreeViewer(g1);
fTree.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
fTree.getTree().getAccessible().addAccessibleListener(
new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
e.result = Messages.RefreshPolicyTab_resourcesTreeLabel;
}
}
);
fTree.setContentProvider(new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof _Entry) {
return ((_Entry) parentElement).getChildren();
}
if (parentElement instanceof _Exception_Node) {
return ((_Exception_Node)parentElement).getChildren();
}
return null;
}
public Object getParent(Object element) {
if (element instanceof _Entry)
return ((_Entry)element).parent;
if (element instanceof _Exception_Node)
return ((_Exception_Node)element).parent;
if (element instanceof _Exclusion_Instance)
return ((_Exclusion_Instance)element).parent;
return null;
}
public boolean hasChildren(Object element) {
return (element instanceof _Entry || element instanceof _Exception_Node);
}
public Object[] getElements(Object inputElement) {
return fSrc.toArray(new _Entry[fSrc.size()]);
}
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}});
fTree.setLabelProvider(new LabelProvider() {
@Override
public Image getImage(Object element) {
if (element instanceof _Exception_Node)
return IMG_EXCEPTION;
else if (element instanceof _Entry) {
_Entry entry = (_Entry) element;
if (entry.isExclusion()) {
return getImageForExclusionType(entry.exclusion.getExclusionType());
}
return getImageForResource(entry.resourceToRefresh);
}
else if (element instanceof _Exclusion_Instance){
return getImageForExclusionType(((_Exclusion_Instance) element).instance.getExclusionType());
}
else
return null;
}
});
fTree.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof TreeSelection) {
Object sel = ((TreeSelection)selection).getFirstElement();
if ( sel != null && sel instanceof _Exception_Node) {
fTree.setSelection(null);
}
}
updateButtons();
}
});
fTree.setInput(fSrc);
updateButtons();
}
private Image getImageForResource(IResource resource) {
switch (resource.getType()) {
case IResource.FILE:
return IMG_FILE;
case IResource.FOLDER:
case IResource.PROJECT:
return IMG_FOLDER;
default:
return IMG_RESOURCE;
}
}
private Image getImageForExclusionType(ExclusionType exclusionType) {
switch (exclusionType) {
case FILE:
return IMG_FILE;
case FOLDER:
return IMG_FOLDER;
case RESOURCE:
default:
return IMG_RESOURCE;
}
}
private void generateTreeContent(IProject project) {
Iterator<IResource> iterator = fResourcesToRefresh.iterator();
while (iterator.hasNext()) {
_Entry top = new _Entry(iterator.next());
fSrc.add(top);
}
}
@Override
protected void performApply(ICResourceDescription src, ICResourceDescription dst) {
performOK();
}
@Override
protected void performDefaults() {
// TODO Auto-generated method stub
}
@Override
protected void updateData(ICResourceDescription cfg) {
// TODO Auto-generated method stub
}
@Override
protected void updateButtons() {
TreeItem[] sel = fTree.getTree().getSelection();
buttonSetEnabled(IDX_ADD_RESOURCE, true);
buttonSetEnabled(IDX_ADD_EXCEPTION, sel.length == 1 && sel[0].getData() instanceof _Entry);
buttonSetEnabled(IDX_EDIT, sel.length == 1 && sel[0].getData() instanceof _Entry && ((_Entry) sel[0].getData()).isExclusion());
buttonSetEnabled(IDX_DELETE, sel.length == 1 && (sel[0].getData() instanceof _Entry || sel[0].getData() instanceof _Exclusion_Instance));
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.newui.AbstractCPropertyTab#buttonPressed(int)
*/
@Override
protected void buttonPressed(int x) {
Shell shell = usercomp.getShell();
TreeSelection selection = (TreeSelection) fTree.getSelection();
switch (x) {
case IDX_ADD_RESOURCE:
//TODO: Phase one implementation - folders only - need to change this for Phase two
ContainerSelectionDialog addResourceDialog = new ContainerSelectionDialog(shell, null, true, Messages.RefreshPolicyTab_addResourceDialogDescription);
addResourceDialog.setTitle(Messages.RefreshPolicyTab_addResourceDialogTitle);
if (addResourceDialog.open() == Window.OK) {
Object[] result = addResourceDialog.getResult();
for (int i = 0; i < result.length; i++) {
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) result[i]);
_Entry newResource = new _Entry(resource);
//update the model element in this tab
fResourcesToRefresh.add(resource);
//update tree
fSrc.add(newResource);
}
fTree.refresh();
}
break;
case IDX_ADD_EXCEPTION:
if (selection == null)
break;
_Entry sel = (_Entry) selection.getFirstElement();
RefreshPolicyExceptionDialog addExceptionDialog;
if (sel.isExclusion()) {
addExceptionDialog = new RefreshPolicyExceptionDialog(shell, sel.exclusion, true);
} else {
addExceptionDialog = new RefreshPolicyExceptionDialog(shell, sel.resourceToRefresh, getExclusions(sel.resourceToRefresh), true);
}
if (addExceptionDialog.open() == Window.OK) {
RefreshExclusion newExclusion = addExceptionDialog.getResult();
//update tree & the working copy of the model elements in this tab
sel.addException(newExclusion);
fTree.refresh();
}
fTree.refresh();
break;
case IDX_EDIT: //can only edit a refresh exclusion
if (selection == null)
break;
_Entry selectedExclusion = (_Entry) selection.getFirstElement();
RefreshPolicyExceptionDialog editExceptionDialog;
editExceptionDialog = new RefreshPolicyExceptionDialog(shell, selectedExclusion.exclusion, false);
if (editExceptionDialog.open() == Window.OK) {
RefreshExclusion updatedExclusion = editExceptionDialog.getResult();
//update tree
selectedExclusion.updateException(updatedExclusion);
fTree.refresh();
}
fTree.refresh();
break;
case IDX_DELETE:
if (selection == null)
break;
if (selection.getFirstElement() instanceof _Entry) {
_Entry sel1 = (_Entry) selection.getFirstElement();
boolean remove = false;
if (sel1.exceptions_node != null) {
String question;
if (sel1.isExclusion()) {
question = Messages.RefreshPolicyTab_deleteConfirmationDialog_question_exception;
} else {
question = Messages.RefreshPolicyTab_deleteConfirmationDialog_question_resource;
}
if (MessageDialog.openQuestion(shell, Messages.RefreshPolicyTab_deleteConfirmationDialog_title, question)) {
remove = true;
}
} else {
remove = true;
}
if (remove) {
//update tree & the working copy of the model elements in this tab
sel1.remove();
fTree.refresh();
}
} else { //exclusion instance
_Exclusion_Instance sel1 = (_Exclusion_Instance) selection.getFirstElement();
//update tree & the working copy of the model elements in this tab
sel1.remove();
fTree.refresh();
}
break;
default:
break;
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.newui.AbstractCPropertyTab#performOK()
*/
@Override
protected void performOK() {
fManager.setResourcesToRefresh(fProject, fResourcesToRefresh);
Iterator<IResource> iterator = fResourcesToRefresh.iterator();
while (iterator.hasNext()) {
IResource resource = iterator.next();
fManager.clearExclusions(resource);
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
fManager.setExclusions(resource, exclusions);
}
}
}

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.core.resources;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.text.MessageFormat;
@ -101,7 +100,12 @@ public class RefreshScopeManager {
*/
public List<IResource> getResourcesToRefresh(IProject project) {
getProjectToResourcesMap();
List<IResource> retval = new LinkedList<IResource>(fProjectToResourcesMap.get(project));
LinkedHashSet<IResource> resources = fProjectToResourcesMap.get(project);
List<IResource> retval;
if (resources == null)
retval= new LinkedList<IResource>();
else
retval= new LinkedList<IResource>(resources);
return retval;
}
@ -361,7 +365,16 @@ public class RefreshScopeManager {
public void clearExclusions(IResource resource) {
getResourcesToExclusionsMap();
List<RefreshExclusion> exclusions = fResourceToExclusionsMap.get(resource);
exclusions.clear();
if(exclusions != null) {
exclusions.clear();
}
}
public void setExclusions(IResource resource, List<RefreshExclusion> newExclusions) {
getResourcesToExclusionsMap();
List<RefreshExclusion> exclusions = new LinkedList<RefreshExclusion>(newExclusions);
fResourceToExclusionsMap.put(resource, exclusions);
}
public void clearAllExclusions() {

View file

@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.resources;
import org.eclipse.core.resources.IResource;
/**
*
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
*
* @author vkong
* @since 5.3
*
*/
public class ResourceExclusion extends RefreshExclusion {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusion#getName()
*/
@Override
public String getName() {
// TODO Auto-generated method stub
return "Resource Exclusions";
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.RefreshExclusion#testExclusion(org.eclipse.core.resources.IResource)
*/
@Override
public boolean testExclusion(IResource resource) {
// TODO Auto-generated method stub
return false;
}
}

View file

@ -601,3 +601,6 @@ transfer.EditorAppearance.name = C/C++ Editor Appearance
transfer.EditorAppearance.description = Preference related to how the editor presents the edited code to the user (including colors, fonts, hovers, foldings, etc...)
transfer.EditorBehavior.name = C/C++ Editor Behavior
transfer.EditorBehavior.description = Preference related to how the editor process the edited code (typing, save action, etc...)
# Refresh Exclusion Contributors
RefreshExclusionContributor.name = Resources

View file

@ -3951,5 +3951,13 @@
</transfer>
</extension>
<extension
point="org.eclipse.cdt.ui.RefreshExclusionContributor">
<exclusionContributor
class="org.eclipse.cdt.ui.resources.ResourceExclusionContributor"
id="org.eclipse.cdt.ui.ResourceExclusionContributor"
name="%RefreshExclusionContributor.name">
</exclusionContributor>
</extension>
</plugin>

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.resources;
import org.eclipse.osgi.util.NLS;
/**
* @since 5.3
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.resources.messages"; //$NON-NLS-1$
public static String RefreshPolicyExceptionDialog_exceptionTypeResources;
public static String RefreshPolicyExceptionDialog_addButtonLabel;
public static String RefreshPolicyExceptionDialog_SelectResourceDialogMessage;
public static String RefreshPolicyExceptionDialog_SelectResourceDialogTitle;
public static String RefreshPolicyExceptionDialog_deleteButtonLabel;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,290 @@
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.resources;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
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.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.w3c.dom.Element;
import org.eclipse.cdt.core.resources.ExclusionInstance;
import org.eclipse.cdt.core.resources.ExclusionType;
import org.eclipse.cdt.core.resources.RefreshExclusion;
import org.eclipse.cdt.core.resources.ResourceExclusion;
/**
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will work or
* that it will remain the same. Please do not use this API without consulting
* with the CDT team.
*
* @author vkong
* @since 5.3
*
*/
public class ResourceExclusionContributor extends RefreshExclusionContributor {
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createExclusion()
*/
@Override
public RefreshExclusion createExclusion() {
ResourceExclusion newExclusion = new ResourceExclusion();
newExclusion.setContributorId(getID());
//TODO change this for Phase 2
newExclusion.setExclusionType(ExclusionType.FOLDER);
return newExclusion;
}
private IResource getResourceRoot(RefreshExclusion exclusion) {
if (exclusion.getParentExclusion() != null) {
return getResourceRoot(exclusion.getParentExclusion());
}
return exclusion.getParentResource();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createProperiesUI(org.eclipse.swt.widgets.Composite, org.eclipse.cdt.core.resources.RefreshExclusion)
*/
@Override
public void createProperiesUI(Composite parent, final RefreshExclusion exclusion) {
final Shell shell = parent.getShell();
Group g = new Group(parent, SWT.NONE);
g.setText(Messages.RefreshPolicyExceptionDialog_exceptionTypeResources);
g.setLayout(new GridLayout(1, false));
GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.verticalSpan = 2;
g.setLayoutData(gridData);
final List exceptionsList = new List(g, SWT.NONE);
gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.verticalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.minimumHeight = 250;
gridData.minimumWidth = 275;
exceptionsList.setLayoutData(gridData);
final HashMap<String, ExclusionInstance> exclusionInstanceStrings = new LinkedHashMap<String, ExclusionInstance>();
final HashMap<String, Object> exclusionInstanceResources = new LinkedHashMap<String, Object>();
java.util.List<ExclusionInstance> exclusionInstances = exclusion.getExclusionInstances();
//populate exclusion instance list
if (exclusionInstances != null) {
Iterator<ExclusionInstance> iterator = exclusionInstances.iterator();
while (iterator.hasNext()) {
ExclusionInstance exclusionInstance = iterator.next();
String name = exclusionInstance.getDisplayString();
exceptionsList.add(name);
exclusionInstanceStrings.put(name, exclusionInstance);
exclusionInstanceResources.put(name, exclusionInstance.getResource());
}
}
Composite buttonComp = new Composite(parent, SWT.NONE);
buttonComp.setLayout(new GridLayout(1, false));
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gridData.minimumWidth = 100;
buttonComp.setLayoutData(gridData);
Button addButton = new Button(buttonComp, SWT.NONE);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
addButton.setLayoutData(gridData);
addButton.setText(Messages.RefreshPolicyExceptionDialog_addButtonLabel);
addButton.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(shell, WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(),
new ITreeContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
public Object getParent(Object element) {
if (element instanceof IResource) {
return ((IResource) element).getParent();
}
return null;
}
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IContainer) {
IContainer container = (IContainer) parentElement;
if (container.isAccessible()) {
try {
java.util.List<IResource> children = new ArrayList<IResource>();
IResource[] members = container.members();
for (int i = 0; i < members.length; i++) {
if (members[i].getType() == IResource.FOLDER) {
children.add(members[i]);
}
}
return children.toArray();
} catch (CoreException e) {
// this should never happen because we call #isAccessible before invoking #members
}
}
}
return new Object[0];
}
} );
dialog.setInput(getResourceRoot(exclusion));
if (exclusionInstanceResources.values().size() > 0) {
dialog.setInitialElementSelections(Arrays.asList(exclusionInstanceResources.values().toArray()));
}
dialog.setMessage(Messages.RefreshPolicyExceptionDialog_SelectResourceDialogMessage);
dialog.setTitle(Messages.RefreshPolicyExceptionDialog_SelectResourceDialogTitle);
if (dialog.open() == Window.OK) {
Object[] selection = dialog.getResult();
exceptionsList.removeAll();
exclusionInstanceResources.clear();
final HashMap<String, ExclusionInstance> oldExclusionInstanceStrings = new LinkedHashMap<String, ExclusionInstance>(exclusionInstanceStrings);
exclusionInstanceStrings.clear();
for (int i = 0; i < selection.length; i++) {
Object selected = selection[i];
if (selected instanceof IFolder) {
IPath path = ((IFolder)selected).getFullPath();
IPath relativePath = path.makeRelativeTo(getResourceRoot(exclusion).getFullPath());
exceptionsList.add(relativePath.toString());
ExclusionInstance instance = oldExclusionInstanceStrings.get(relativePath.toString());
if (instance == null) {
instance = new ExclusionInstance();
instance.setExclusionType(ExclusionType.FOLDER);
instance.setParentExclusion(exclusion);
instance.setResource((IResource) selected);
instance.setDisplayString(relativePath.toString());
exclusion.addExclusionInstance(instance);
} else {
oldExclusionInstanceStrings.remove(relativePath.toString());
}
exclusionInstanceStrings.put(instance.getDisplayString(), instance);
exclusionInstanceResources.put(instance.getDisplayString(), selected);
}
}
//remove deprecated exclusion instances
oldExclusionInstanceStrings.keySet();
Iterator<String> iterator = oldExclusionInstanceStrings.keySet().iterator();
while (iterator.hasNext()) {
String toRemove = iterator.next();
ExclusionInstance instanceToRemove = oldExclusionInstanceStrings.get(toRemove);
exclusion.removeExclusionInstance(instanceToRemove);
iterator.remove();
}
}
}
});
Button deleteButton = new Button(buttonComp, SWT.NONE);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
deleteButton.setLayoutData(gridData);
deleteButton.setText(Messages.RefreshPolicyExceptionDialog_deleteButtonLabel);
deleteButton.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
String[] selected = exceptionsList.getSelection();
if (selected.length < 1)
return;
for (int i = 0; i < selected.length; i++) {
String folderToRemove = selected[i];
ExclusionInstance instanceToRemove = exclusionInstanceStrings.get(folderToRemove);
// Iterator<Object> iterator = selectedFolders.iterator();
// while (iterator.hasNext()) {
// IPath path = ((IFolder)iterator.next()).getFullPath();
// IPath relativePath = path.makeRelativeTo(getResourceRoot(exclusionRoot).getFullPath());
// if (relativePath.toString().compareTo(folderToRemove) == 0) {
// iterator.remove();
// break;
// }
// }
exclusion.removeExclusionInstance(instanceToRemove);
exclusionInstanceStrings.remove(folderToRemove);
exclusionInstanceResources.remove(folderToRemove);
}
exceptionsList.remove(exceptionsList.getSelectionIndices());
}
});
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.resources.RefreshExclusionContributor#createExclusionFromXML(org.w3c.dom.Element)
*/
@Override
public RefreshExclusion createExclusionFromXML(Element exclusionElement) {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -0,0 +1,16 @@
###############################################################################
# Copyright (c) 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1_0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# IBM Corporation - Initial API and implementation
###############################################################################
RefreshPolicyExceptionDialog_exceptionTypeResources=Resources
RefreshPolicyExceptionDialog_addButtonLabel=Add...
RefreshPolicyExceptionDialog_deleteButtonLabel=Delete
RefreshPolicyExceptionDialog_SelectResourceDialogTitle=Select resource for exception
RefreshPolicyExceptionDialog_SelectResourceDialogMessage=Select resource: