blob: 4b46f0c2e8958f1d2658a07e95b8981223a719ea [file] [log] [blame]
/*
* Copyright (c) 2014, 2015 Eike Stepper (Berlin, Germany) 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:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.oomph.predicates.provider;
import org.eclipse.oomph.predicates.PredicatesPackage;
import org.eclipse.oomph.predicates.RepositoryPredicate;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* This is the item provider adapter for a {@link org.eclipse.oomph.predicates.RepositoryPredicate} object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class RepositoryPredicateItemProvider extends PredicateItemProvider
{
private static final IWorkspaceRoot WORKSPACE_ROOT = ResourcesPlugin.getWorkspace().getRoot();
/**
* This constructs an instance from a factory and a notifier.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public RepositoryPredicateItemProvider(AdapterFactory adapterFactory)
{
super(adapterFactory);
}
/**
* This returns the property descriptors for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object)
{
if (itemPropertyDescriptors == null)
{
super.getPropertyDescriptors(object);
addProjectPropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
/**
* This adds a property descriptor for the Project feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
protected void addProjectPropertyDescriptor(Object object)
{
itemPropertyDescriptors.add(new ItemPropertyDescriptor(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(),
getString("_UI_RepositoryPredicate_project_feature"), getString("_UI_RepositoryPredicate_project_description"),
PredicatesPackage.Literals.REPOSITORY_PREDICATE__PROJECT, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null)
{
@Override
public Collection<?> getChoiceOfValues(Object object)
{
List<IProject> result = new ArrayList<IProject>();
for (IProject project : WORKSPACE_ROOT.getProjects())
{
result.add(project);
}
return result;
}
});
}
/**
* This returns RepositoryPredicate.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object getImage(Object object)
{
return overlayImage(object, getResourceLocator().getImage("full/obj16/RepositoryPredicate"));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected boolean shouldComposeCreationImage()
{
return true;
}
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String getText(Object object)
{
IProject project = ((RepositoryPredicate)object).getProject();
return project == null ? getString("_UI_RepositoryPredicate_type") : "In same repository as " + project.getName();
}
/**
* This handles model notifications by calling {@link #updateChildren} to update any cached
* children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void notifyChanged(Notification notification)
{
updateChildren(notification);
switch (notification.getFeatureID(RepositoryPredicate.class))
{
case PredicatesPackage.REPOSITORY_PREDICATE__PROJECT:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
super.notifyChanged(notification);
}
@Override
protected Command createPrimaryDragAndDropCommand(EditingDomain domain, Object owner, float location, int operations, int operation, Collection<?> collection)
{
return new BaseDragAndDropCommand(domain, owner, location, operations, operation, collection)
{
@Override
protected boolean analyzeForNonContainment(Command command)
{
return true;
}
};
}
@Override
protected Command createSetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Object value)
{
if (feature == null)
{
if (value instanceof Collection<?>)
{
for (Object item : (Collection<?>)value)
{
if (item instanceof IProject)
{
IProject project = (IProject)item;
return new SetCommand(domain, owner, PredicatesPackage.Literals.REPOSITORY_PREDICATE__PROJECT, project);
}
}
}
}
return super.createSetCommand(domain, owner, feature, value);
}
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object)
{
super.collectNewChildDescriptors(newChildDescriptors, object);
}
}