| /* |
| * Copyright (c) 2014, 2015 Eike Stepper (Loehne, Germany) and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v20.html |
| * |
| * Contributors: |
| * Eike Stepper - initial API and implementation |
| */ |
| package org.eclipse.oomph.setup.projects.impl; |
| |
| import org.eclipse.oomph.setup.SetupTaskContext; |
| import org.eclipse.oomph.setup.impl.SetupTaskImpl; |
| import org.eclipse.oomph.setup.projects.PathVariableTask; |
| import org.eclipse.oomph.setup.projects.ProjectsPackage; |
| import org.eclipse.oomph.util.ObjectUtil; |
| |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| |
| import org.eclipse.core.resources.IPathVariableManager; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| |
| import java.net.URI; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * An implementation of the model object '<em><b>Path Variable Task</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * </p> |
| * <ul> |
| * <li>{@link org.eclipse.oomph.setup.projects.impl.PathVariableTaskImpl#getName <em>Name</em>}</li> |
| * <li>{@link org.eclipse.oomph.setup.projects.impl.PathVariableTaskImpl#getURI <em>URI</em>}</li> |
| * </ul> |
| * |
| * @generated |
| */ |
| public class PathVariableTaskImpl extends SetupTaskImpl implements PathVariableTask |
| { |
| /** |
| * The default value of the '{@link #getName() <em>Name</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getName() |
| * @generated |
| * @ordered |
| */ |
| protected static final String NAME_EDEFAULT = null; |
| |
| /** |
| * The cached value of the '{@link #getName() <em>Name</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getName() |
| * @generated |
| * @ordered |
| */ |
| protected String name = NAME_EDEFAULT; |
| |
| /** |
| * The default value of the '{@link #getURI() <em>URI</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getURI() |
| * @generated |
| * @ordered |
| */ |
| protected static final String URI_EDEFAULT = null; |
| |
| /** |
| * The cached value of the '{@link #getURI() <em>URI</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getURI() |
| * @generated |
| * @ordered |
| */ |
| protected String uRI = URI_EDEFAULT; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected PathVariableTaskImpl() |
| { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() |
| { |
| return ProjectsPackage.Literals.PATH_VARIABLE_TASK; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public String getName() |
| { |
| return name; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void setName(String newName) |
| { |
| String oldName = name; |
| name = newName; |
| if (eNotificationRequired()) |
| { |
| eNotify(new ENotificationImpl(this, Notification.SET, ProjectsPackage.PATH_VARIABLE_TASK__NAME, oldName, name)); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public String getURI() |
| { |
| return uRI; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public void setURI(String newURI) |
| { |
| String oldURI = uRI; |
| uRI = newURI; |
| if (eNotificationRequired()) |
| { |
| eNotify(new ENotificationImpl(this, Notification.SET, ProjectsPackage.PATH_VARIABLE_TASK__URI, oldURI, uRI)); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Object eGet(int featureID, boolean resolve, boolean coreType) |
| { |
| switch (featureID) |
| { |
| case ProjectsPackage.PATH_VARIABLE_TASK__NAME: |
| return getName(); |
| case ProjectsPackage.PATH_VARIABLE_TASK__URI: |
| return getURI(); |
| } |
| return super.eGet(featureID, resolve, coreType); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eSet(int featureID, Object newValue) |
| { |
| switch (featureID) |
| { |
| case ProjectsPackage.PATH_VARIABLE_TASK__NAME: |
| setName((String)newValue); |
| return; |
| case ProjectsPackage.PATH_VARIABLE_TASK__URI: |
| setURI((String)newValue); |
| return; |
| } |
| super.eSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) |
| { |
| switch (featureID) |
| { |
| case ProjectsPackage.PATH_VARIABLE_TASK__NAME: |
| setName(NAME_EDEFAULT); |
| return; |
| case ProjectsPackage.PATH_VARIABLE_TASK__URI: |
| setURI(URI_EDEFAULT); |
| return; |
| } |
| super.eUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) |
| { |
| switch (featureID) |
| { |
| case ProjectsPackage.PATH_VARIABLE_TASK__NAME: |
| return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); |
| case ProjectsPackage.PATH_VARIABLE_TASK__URI: |
| return URI_EDEFAULT == null ? uRI != null : !URI_EDEFAULT.equals(uRI); |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public String toString() |
| { |
| if (eIsProxy()) |
| { |
| return super.toString(); |
| } |
| |
| StringBuffer result = new StringBuffer(super.toString()); |
| result.append(" (name: "); |
| result.append(name); |
| result.append(", uRI: "); |
| result.append(uRI); |
| result.append(')'); |
| return result.toString(); |
| } |
| |
| @Override |
| public Object getOverrideToken() |
| { |
| return createToken(getName()); |
| } |
| |
| @Override |
| public int getProgressMonitorWork() |
| { |
| return 0; |
| } |
| |
| public boolean isNeeded(SetupTaskContext context) throws Exception |
| { |
| IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); |
| URI value = pathVariableManager.getURIValue(getName()); |
| return !ObjectUtil.equals(value == null ? null : value.toString(), getURI()); |
| } |
| |
| public void perform(SetupTaskContext context) throws Exception |
| { |
| String name = getName(); |
| String uri = getURI(); |
| context.log("Setting path variable " + name + " = " + uri); |
| |
| IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); |
| pathVariableManager.setURIValue(name, uri == null ? null : new URI(uri)); |
| } |
| |
| } // PathVariableTaskImpl |