Exemplo n.º 1
0
        public CreateTestViewModel(ITestService testService,
                                   IToolboxViewModel toolboxViewModel,
                                   IFormSurfaceViewModel formSurfaceViewModel,
                                   IPropertiesViewModel propertiesViewModel,
                                   IPageService pageService)
            : base(pageService)
        {
            m_testService        = testService;
            ToolboxViewModel     = toolboxViewModel;
            FormSurfaceViewModel = formSurfaceViewModel;
            PropertiesViewModel  = propertiesViewModel;

            ConfirmCommand = new DelegateCommand(Confirm);
            CancelCommand  = new DelegateCommand(Cancel);
        }
    private void SelectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
      var applicableActionType = (e.Action == NotifyCollectionChangedAction.Add) ||
        (e.Action == NotifyCollectionChangedAction.Replace) ||
        (e.Action == NotifyCollectionChangedAction.Reset);
      
      if ((!applicableActionType) || (currentSelectionService.CurrentSelection.Count != 1))
      {
        Clear();
        return;
      }

      var selectedItem =  currentSelectionService.CurrentSelection.FirstOrDefault() as IView;
      if ((selectedItem == null) || (selectedItem.ViewModel == null))
      {
        Clear();
        return;
      }

      lastProperties = selectedItem.ViewModel.Properties;
      RecalculateItems();
    }
    public static IEnumerable<PropertySingleItem> Build(IPropertiesViewModel propertiesViewModel)
    {
      var propertySingleItems = new List<PropertySingleItem>();
      var connectorPropertiesViewModel = propertiesViewModel as ConnectorPropertiesViewModel;
      if (connectorPropertiesViewModel != null)
      {
        var vm = connectorPropertiesViewModel;
        var namePropertyValue = new PropertyStringValueViewModel(() => {return vm.Name;}, o => {vm.Name = (string)o;} );
        var nameProperty = new PropertySingleItem("Name", namePropertyValue);
        propertySingleItems.Add(nameProperty);

        var isSetPropertyWalue = new PropertyBoolValueViewModel(() => {return vm.IsSet;}, o => {vm.IsSet = (bool)o;} );
        var isSetProperty = new PropertySingleItem("IsSet", isSetPropertyWalue);
        propertySingleItems.Add(isSetProperty);

        var pipeVm = vm.DomainProperties as PipeConnectorDomainPropertiesViewModel;
        if (pipeVm != null)
        {
          var pressurePropertyWalue = new PropertyDoubleValueViewModel(
            () => pipeVm.Pressure, o => {pipeVm.Pressure = (double)o;} );
          var pressureProperty = new PropertySingleItem("Pressure", pressurePropertyWalue);

          var temperaturePropertyWalue = new PropertyDoubleValueViewModel(
            () => pipeVm.Temperature, o => {pipeVm.Temperature = (double)o;} );
          var temperatureProperty = new PropertySingleItem("Temperature", temperaturePropertyWalue);

          propertySingleItems.Add(pressureProperty);
          propertySingleItems.Add(temperatureProperty);
        }

        return propertySingleItems;
      }
      var elementPropertiesViewModel = propertiesViewModel as ElementPropertiesViewModel;
      if (elementPropertiesViewModel != null)
      {
        var vm = elementPropertiesViewModel;
        var namePropertyWalue = new PropertyStringValueViewModel(() => vm.Name, o => {vm.Name = (string)o;} );
        var nameProperty = new PropertySingleItem("Name", namePropertyWalue);

        var visualProperties = vm.ElementVisualPropertiesViewModel;
        var coords = visualProperties.Coords;

        var xPropertyWalue = new PropertyDoubleValueViewModel(() => coords.X, o => {coords.X = (double)o;} );
        var xProperty = new PropertySingleItem("X", xPropertyWalue);

        var yPropertyWalue = new PropertyDoubleValueViewModel(() => coords.Y, o => {coords.Y = (double)o;} );
        var yProperty = new PropertySingleItem("Y", yPropertyWalue); 

        propertySingleItems.Add(nameProperty);
        propertySingleItems.Add(xProperty);
        propertySingleItems.Add(yProperty);
        return propertySingleItems;
      }
      return propertySingleItems;
    }