blob: e5dcdd26f2895dc5366c662194dc1a154920eea3 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.widgets;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osee.framework.db.connection.exception.AttributeDoesNotExist;
import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.validation.IOseeValidator;
import org.eclipse.osee.framework.skynet.core.validation.OseeValidator;
import org.eclipse.osee.framework.ui.plugin.util.Result;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
public class XComboDam extends XCombo implements IArtifactWidget {
private Artifact artifact;
private String attributeTypeName;
public XComboDam(String displayLabel) {
super(displayLabel);
}
public void setArtifact(Artifact artifact, String attrName) throws OseeCoreException {
this.artifact = artifact;
this.attributeTypeName = attrName;
try {
String value = artifact.getSoleAttributeValue(attributeTypeName);
super.set(value.toString());
} catch (AttributeDoesNotExist ex) {
super.set("");
}
}
@Override
public void saveToArtifact() throws OseeCoreException {
try {
if (!Strings.isValid(data)) {
artifact.deleteSoleAttribute(attributeTypeName);
} else {
String enteredValue = get();
artifact.setSoleAttributeValue(attributeTypeName, enteredValue);
}
} catch (Exception ex) {
OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
}
}
/* (non-Javadoc)
* @see org.eclipse.osee.framework.ui.skynet.widgets.IArtifactWidget#isDirty()
*/
@Override
public Result isDirty() throws OseeCoreException {
try {
String enteredValue = get();
String storedValue = artifact.getSoleAttributeValue(attributeTypeName);
if (!enteredValue.equals(storedValue)) {
return new Result(true, attributeTypeName + " is dirty");
}
} catch (AttributeDoesNotExist ex) {
if (!get().equals("")) return new Result(true, attributeTypeName + " is dirty");
}
return Result.FalseResult;
}
/* (non-Javadoc)
* @see org.eclipse.osee.framework.ui.skynet.widgets.XText#isValid()
*/
@Override
public IStatus isValid() {
IStatus status = super.isValid();
if (status.isOK()) {
status = OseeValidator.getInstance().validate(IOseeValidator.SHORT, artifact, attributeTypeName, get());
}
return status;
}
/* (non-Javadoc)
* @see org.eclipse.osee.framework.ui.skynet.widgets.IArtifactWidget#revert()
*/
@Override
public void revert() throws OseeCoreException {
setArtifact(artifact, attributeTypeName);
}
}