/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.ui.properties.sdt;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelUtil;
import org.teiid.designer.ui.UiPlugin;
import org.teiid.designer.ui.editors.ModelEditorManager;
import org.teiid.designer.ui.properties.ReadOnlyPropertyDescriptor;
import org.teiid.designer.ui.viewsupport.ModelUtilities;
/**
* ModelResourceComboBoxPropertyDescriptor
*
* @since 8.0
*/
public class ModelResourceComboBoxPropertyDescriptor extends ComboBoxPropertyDescriptor {
private EObject owner;
private boolean isEditable = true;
private boolean showReadOnlyDialog = true;
/**
* Construct an instance of RuntimeTypePropertyDescriptor.
* @param id
* @param displayName
* @param valuesArray
*/
public ModelResourceComboBoxPropertyDescriptor(EObject owner, Object id, String displayName, String[] valuesArray) {
this(id, displayName, valuesArray);
this.owner = owner;
}
public ModelResourceComboBoxPropertyDescriptor(Object id, String displayName, String[] valuesArray) {
super(id, displayName, valuesArray);
}
//============================================================
// Instance Methods
//============================================================
public void setShowReadOnlyDialog(boolean enable) {
showReadOnlyDialog = enable;
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertyDescriptor#getCategory()
*/
@Override
public String getCategory() {
return NodePropertyDescriptor.CATEGORY;
}
/* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertyDescriptor#createPropertyEditor(org.eclipse.swt.widgets.Composite)
*/
@Override
public CellEditor createPropertyEditor(Composite parent) {
if (!isEditable) {
return null;
}
// check failure conditions: ModelResource is null, or read-only, or not open in an editor
ModelResource modelResource = ModelUtilities.getModelResourceForModelObject(this.owner);
if (modelResource == null) { // if the modelResource is null, we can't edit the properties
return null;
}
if (ModelUtil.isIResourceReadOnly(modelResource.getResource())) {
if (showReadOnlyDialog) {
Shell shell = UiPlugin.getDefault().getCurrentWorkbenchWindow().getShell();
MessageDialog.openError(
shell,
ReadOnlyPropertyDescriptor.READ_ONLY_TITLE,
ReadOnlyPropertyDescriptor.READ_ONLY_MESSAGE);
}
return null;
}
IFile file = (IFile)modelResource.getResource();
if (file != null) {
if (!ModelEditorManager.isOpen(file)) {
// can't modify a property value on an EObject if it's ModelEditor is not open.
Shell shell = UiPlugin.getDefault().getCurrentWorkbenchWindow().getShell();
if (MessageDialog
.openQuestion(
shell,
ModelEditorManager.OPEN_EDITOR_TITLE,
ModelEditorManager.OPEN_EDITOR_MESSAGE)) {
ModelEditorManager.open(this.owner, true);
}
return null;
}
}
return super.createPropertyEditor(parent);
}
public boolean isEditable() {
return this.isEditable;
}
public void setEditable(boolean isEditable) {
this.isEditable = isEditable;
}
}