// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file contains the business object configuration.
//
// It shows how to customize custom business objects
// and how to create your own business object
// representation using JTGO and JViews Graphic objects.
//
// This example also shows how to use pseudoclasses
// and how to customize the business object representation
// based on these values.
//
// This is an advanced example, whose purpose is to
// illustrate how to create composite graphic objects
// using CSS.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Configure custom business class: LinkElement
//
// These business objects are displayed using the
// predefined custom business object representation.
// JTGO provides a default representation for
// links. Please refer to the User's Manual for a 
// complete list of properties that apply to this
// business object.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

object.LinkElement {
  labelFont: "arial-plain-8";
  label: @name;
  foreground: #FFCFCFDF;
  alternateColor: #FFC0C0D0;
  lineWidth: 7f;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Configure custom business class: NetworkElement
//
// A custom NetworkElement is graphically represented
// as a rectangle with an icon that represents the 
// business class. This element is called the object
// base. It also contains the following decorations:
// - Label: that represents the 'name' attribute and
//          which is placed below the object base
// - Alarm balloon: that represents the 'newAlarms'
//          attribute and which is placed at the top
//          right corner of the object base.
// - Test balloon: that represents the 'test' attribute
//          and which is attached to the bottom right
//          corner of the object base.
// - Information icon and Information window: that
//          represents the 'contact' and 'site'
//          attributes. The Information Icon is placed
//          at the top left corner of the object base.
//          An object interactor is defined to the
//          Information icon to toggle the visibility
//          of the Information window whenever you click
//          on the icon.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

object.NetworkElement {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+attachmentLayout;
  children[0]: @+neBase;
  children[1]: @+neLabel;
  children[2]: '';
  children[3]: '';
  children[4]: '';
  toolTipText: @name;
  constraints[1]: @+neLabelConstraint;
  constraints[2]: '';
  constraints[3]: '';
  constraints[4]: '';
}
object.NetworkElement[site] {
  toolTipText: @site;
}

#attachmentLayout {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentLayout';
}

object.Workstation {
  children[0]: @+workstationBase;
}

object.Server {
  children[0]: @+serverBase;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// The following selectors are used to toggle the
// visibility of each decoration according to a
// specific pseudoclass. 
//
// These selectors are created for illustration only,
// and are used with the buttons placed at the right
// side of the main window. When the buttons are
// toggled, the specific pseudoclass is added or
// removed, therefore changing the graphic 
// representation of the visible objects.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

object.NetworkElement[newAlarms]:showAlarm {
  children[2]: @+neNewAlarms;
  constraints[2]: @+neNewAlarmsConstraints;
}
object.NetworkElement[test]:showTest {
  children[3]: @+neTest;
  constraints[3]: @+neTestConstraints;
}
object.NetworkElement[contact]:showContact {
  children[4]: @+neContact;
  constraints[4]: @+neContactConstraints;
}
object.NetworkElement[contact]:showContact:showInfo {
  children[4]: @+neContactInfo;
  constraints[4]: @+neContactConstraints;
}
object.NetworkElement[site]:showContact {
  children[4]: @+neContact;
  constraints[4]: @+neContactConstraints;
}
object.NetworkElement[site]:showContact:showInfo {
  children[4]: @+neContactInfo;
  constraints[4]: @+neContactConstraints;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Network Element Base
// 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#neBase {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+neBaseLayout;
  children[0]: @+neBaseRectangle;
  children[1]: @+neBaseIcon;
}
#neBaseLayout {
  class: 'ilog.views.graphic.composite.layout.IlvCenteredLayout';
  insets: "12,12,12,12";
}
#neBaseRectangle {
  class: 'ilog.views.graphic.IlvRectangle';
  radius: 5;
  fillOn: true;
  foreground: gray;
  background: yellow;
}
#neBaseIcon {
  class: 'ilog.views.graphic.IlvIcon';
  image: '@|image("workstation.png")';
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Workstation Business Objects
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#workstationBase {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+neBaseLayout;
  children[0]: @+workstationBaseRectangle;
  children[1]: @+neBaseIcon;
}
#workstationBaseRectangle {
  class: 'ilog.views.graphic.IlvRectangle';
  radius: 5;
  fillOn: true;
  foreground: gray;
  background: '#99CCFF';
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Server Business Objects
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#serverBase {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+neBaseLayout;
  children[0]: @+serverBaseRectangle;
  children[1]: @+serverBaseIcon;
}
#serverBaseRectangle {
  class: 'ilog.views.graphic.IlvRectangle';
  radius: 5;
  fillOn: true;
  foreground: gray;
  background: '#FFCC99';
}
#serverBaseIcon {
  class: 'ilog.views.graphic.IlvIcon';
  image: '@|image("server.png")';
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Creates and attaches the Label decoration
// 
// To associate a decoration to an IlpAttribute
// specify the 'ILPATTRIBUTE' property as illustrated 
// below.
//
// Here we show the use of built-in property ILPATTRIBUTE.
//
// This property is used to associate a graphic decoration
// to an attribute in the business model. 
//
// The ILPATTRIBUTE property type is String. Its value 
// should be an attribute name.
//
// Once this association is done, tooltips and interactors
// can be defined in CSS for the business attribute
// and will be displayed/triggered when the event 
// occurs in the decoration graphic.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#neLabel {
  class: 'ilog.views.graphic.IlvText';
  label: @name;
  font: "arial-plain-12";
  foreground: black;
  ILPATTRIBUTE: "name";
}
#neLabelConstraint {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentConstraint';
  hotSpot: TopCenter;
  anchor: BottomCenter;
  offset: 0,3;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Creates and attaches the Alarm Balloon decoration
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#neNewAlarms {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+centeredLayout;
  children[0]: @+neNewAlarmsBalloon;
  children[1]: @+neNewAlarmsLabel;
  ILPATTRIBUTE: "newAlarms";
}
#centeredLayout {
  class: 'ilog.views.graphic.composite.layout.IlvCenteredLayout';
  insets: "5,5,5,5";
}
#neNewAlarmsBalloon {
  class: 'ilog.views.graphic.composite.decoration.IlvRoundRectBalloon';
  orientation: NORTH_EAST;
  pointerDepth: 10;
  shadowThickness: 2;
  radius: 15;
  shadowColor: black;
  borderColor: black;
  balloonColor: '@|valuemap(@=AlarmColorMap, @newAlarms)';
}
#neNewAlarmsLabel {
  class: 'ilog.views.graphic.IlvText';
  label: '@|valuemap(@=AlarmLabelMap, @newAlarms)';
  font: "arial-bold-12";
  foreground: black;
}
#neNewAlarmsConstraints {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentConstraint';
  hotSpot: HotSpot;
  anchor: TopRight;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Creates and attaches the Test Balloon decoration
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#neTest {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+centeredLayout;
  children[0]: @+neTestBalloon;
  children[1]: @+neTestLabel;
  ILPATTRIBUTE: "test";
}
#neTestBalloon {
  class: 'ilog.views.graphic.composite.decoration.IlvRoundRectBalloon';
  orientation: SOUTH_EAST;
  pointerDepth: 10;
  shadowThickness: 2;
  radius: 15;
  shadowColor: black;
  borderColor: black;
  balloonColor: white;
}
#neTestLabel {
  class: 'ilog.views.graphic.IlvText';
  label: '@|valuemap(@=TestLabelMap, @test)';
  font: "arial-bold-12";
  foreground: black;
}
#neTestConstraints {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentConstraint';
  hotSpot: HotSpot;
  anchor: BottomRight;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Creates and attaches the Information Window decoration
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#neContact {
  class: 'ilog.views.graphic.IlvIcon';
  image: '@|image("infoicon.png")';
  ILPATTRIBUTE: "contact";
}

#neContactInfo {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+attachmentLayout;
  children[0]: @+neContact;
  children[1]: @+neContactInfoWindow;
  constraints[1]: @+neContactBalloonConstraints;
}

#neContactInfoWindow {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+centeredLayout;
  children[0]: @+neContactBalloon;
  children[1]: @+neContactBalloonContents;
}

#neContactBalloon {
  class: 'ilog.views.graphic.composite.decoration.IlvRectBalloon';
  orientation: NORTH_WEST;
  pointerDepth: 10;
  shadowThickness: 1;
  radius: 15;
  shadowColor: '#999999';
  borderColor: black;
  balloonColor: '#F2F2F2';
}
#neContactBalloonContents {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+stackerLayout;
  children[0]: @+contactLabel;
  children[1]: @+siteLabel;
}
#stackerLayout {
  class: 'ilog.views.graphic.composite.layout.IlvStackerLayout';
  orientation: BOTTOM;
  alignment: LEFT;
}
#contactLabel[contact] {
  class: 'ilog.views.graphic.IlvText';
  label: '@|resource("SampleMessages", "label.contact.title") + @contact';
  font: "arial-bold-10";
  foreground: blue;
}
#siteLabel[site] {
  class: 'ilog.views.graphic.IlvText';
  label: '@|resource("SampleMessages", "label.site.title") + @site';
  font: "arial-bold-10";
  foreground: blue;
  attribute: "site";
}
#neContactConstraints {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentConstraint';
  hotSpot: BottomRight;
  anchor: TopLeft;
  offset: 10,2;
}
#neContactBalloonConstraints {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentConstraint';
  hotSpot: HotSpot;
  anchor: TopCenter;
  offset: -2,0;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Setting specific tooltips for the alarm balloon and test balloon
// decorations.
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

object."NetworkElement/newAlarms"[newAlarms] {
  toolTipText: '@|valuemap(@=AlarmLabelMap, @newAlarms)';
}
object."NetworkElement/test"[test] {
  toolTipText: '@|resource("SampleMessages", "label.test.status.title") + valuemap(@=TestLabelMap, @test)';
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Setting an interactor to toggle the information 
// window.
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

object."NetworkElement/contact" {
  interactor: @+showInfoInteractor;
}
#showInfoInteractor {
  class: 'ilog.cpl.interactor.IlpDefaultObjectInteractor';
  action[0]: @+contactButton1Action;
}
#contactButton1Action {
  class: 'ilog.cpl.interactor.IlpGestureAction';
  gesture: BUTTON1_CLICKED;
  action: @+toggleContactAction;
}
#toggleContactAction {
  class: 'compositeGraphic.ToggleInfoWindowAction';
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Auxiliary instances used for the rendering
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#AlarmLabelMap {
  class: 'ilog.cpl.util.IlpIndexedValueMap';
  keyClass: 'java.lang.Integer';
  valueClass: 'java.lang.String';
  keys[0]: 0;
  keys[1]: 1;
  keys[2]: 2;
  keys[3]: 3;
  keys[4]: 4;
  keys[5]: 5;
  values[0]: '@|resource("SampleMessages", "label.alarm.cleared")';
  values[1]: '@|resource("SampleMessages", "label.alarm.indeterminate")';
  values[2]: '@|resource("SampleMessages", "label.alarm.warning")';
  values[3]: '@|resource("SampleMessages", "label.alarm.minor")';
  values[4]: '@|resource("SampleMessages", "label.alarm.major")';
  values[5]: '@|resource("SampleMessages", "label.alarm.critical")';
}
#AlarmColorMap {
  class: 'ilog.cpl.util.IlpOrderedValueMap';
  keyClass: 'java.lang.Integer';
  valueClass: 'java.awt.Color';
  keys: "0, 1, 2, 3, 4, 5";
  values: "#FFFFFF, #C0C0C0, #FFCC00, #FFB200, #FF0000, #FF0000";
}
#TestLabelMap {
  class: 'ilog.cpl.util.IlpIndexedValueMap';
  keyClass: 'java.lang.Integer';
  valueClass: 'java.lang.String';
  keys[0]: 0;
  keys[1]: 1;
  keys[2]: 2;
  values[0]: '@|resource("SampleMessages", "label.test.unknown")';
  values[1]: '@|resource("SampleMessages", "label.test.testing")';
  values[2]: '@|resource("SampleMessages", "label.test.failed")';
}