package org.jbpm.ui.common.model;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.jbpm.ui.properties.FormatClassPropertyDescriptor;
import org.jbpm.ui.resource.Messages;
import ru.runa.wf.web.forms.format.StringFormat;
public class Variable extends NamedGraphElement {
private String format;
private boolean publicVisibility;
public Variable(String name, String format, boolean publicVisibility) {
super(name);
this.format = format;
this.publicVisibility = publicVisibility;
}
public Variable(String name) {
this(name, StringFormat.class.getName(), false);
}
@Override
protected boolean canNameBeSetFromProperties() {
return false;
}
@Override
protected boolean canSetNameTo(String name) {
if (name.trim().length() == 0) {
return false;
}
return !getProcessDefinition().getVariableNames(true).contains(name);
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
String old = this.format;
this.format = format;
firePropertyChange(PROPERTY_FORMAT, old, this.format);
}
public boolean isPublicVisibility() {
return publicVisibility;
}
public void setPublicVisibility(boolean publicVisibility) {
boolean old = this.publicVisibility;
this.publicVisibility = publicVisibility;
firePropertyChange(PROPERTY_PUBLIC_VISIBILITY, old, this.publicVisibility);
}
@Override
public List<IPropertyDescriptor> getCustomPropertyDescriptors() {
List<IPropertyDescriptor> list = new ArrayList<IPropertyDescriptor>();
list.add(new FormatClassPropertyDescriptor(PROPERTY_FORMAT, Messages.getString("Variable.property.format"), this));
list.add(new PropertyDescriptor(PROPERTY_PUBLIC_VISIBILITY, Messages.getString("Variable.property.publicVisibility")));
return list;
}
@Override
public Object getPropertyValue(Object id) {
if (PROPERTY_FORMAT.equals(id)) {
String className = getFormat();
return className == null ? "" : className;
}
if (PROPERTY_PUBLIC_VISIBILITY.equals(id)) {
return publicVisibility ? Messages.getString("message.yes") : Messages.getString("message.no");
}
return super.getPropertyValue(id);
}
@Override
public void setPropertyValue(Object id, Object value) {
if (PROPERTY_FORMAT.equals(id)) {
setFormat((String) value);
} else {
super.setPropertyValue(id, value);
}
}
}