blob: f39c72adf90a1170de55c2c654414a6a8ca80fc1 [file] [log] [blame]
/*******************************************************************************
* Copyright 2011 Chair for Applied Software Engineering,
* Technische Universitaet Muenchen.
* All rights reserved. This program and the accompanying materials
* are made available under the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
******************************************************************************/
package org.eclipse.emf.emfstore.client.ui.testers;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.emfstore.client.model.ProjectSpace;
import org.eclipse.emf.emfstore.common.model.util.ModelUtil;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
* Tests if the currently selected project space has unsaved changes.
*
* @author mkoegel
*
*/
public class CurrentProjectSpaceHasUnsavedChangesTester extends PropertyTester {
/**
* {@inheritDoc}
*
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[],
* java.lang.Object)
*/
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
return false;
}
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
return false;
}
ISelection selection = activeWorkbenchWindow.getSelectionService().getSelection();
if (selection instanceof StructuredSelection) {
StructuredSelection structuredSelection = (StructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof EObject) {
ProjectSpace projectSpace = ModelUtil.getParent(ProjectSpace.class, ((EObject) firstElement));
if (projectSpace != null) {
return expectedValue.equals(projectSpace.hasUnsavedChanges());
}
}
}
return false;
}
}