示例#1
0
		public static UIElement ForGroup(IDominatorGroup group, IUIRegistrationContext context)
		{
			var panel = new StackPanel();
			var description = CreateDescription(group.Description, forGroup: true);
			panel.Children.Add(description);

			var nestedStackPanel = new StackPanel
			{
				Margin = new Thickness(16, 8, 0, 8)
			};

			foreach (var nested in group.Nested)
			{
				var nestedUI = ForDominator(nested, context);
				nestedStackPanel.Children.Add(nestedUI);
			}

			panel.Children.Add(nestedStackPanel);
			return panel;
		}
示例#2
0
		public static UIElement ForItem(IDominatorItem item, IUIRegistrationContext context)
		{
			var panel = new StackPanel
			{
				Margin = new Thickness(0, 0, 0, DefaultMargin * 2)
			};
			var description = CreateDescription(item.Description, forGroup: false);
			panel.Children.Add(description);

			var switchPanel = new DockPanel
			{
				Margin = new Thickness(0, DefaultMargin, 0, 0)
			};

			var sw = createSwitch();
			sw.VerticalAlignment = VerticalAlignment.Top;
			
			switchPanel.Children.Add(sw);
			// we don't want to use actual Label controls, because they parse '_' underscores as
			// Alt Key shortcuts.
			var errorLabel = CreateTextBlock("");
			errorLabel.VerticalAlignment = VerticalAlignment.Center;
			errorLabel.Foreground = RedBrush;
			errorLabel.Margin = new Thickness(DefaultMargin*2, 0, DefaultMargin, 0);

			var messageLabel = CreateTextBlock("");
			messageLabel.VerticalAlignment = VerticalAlignment.Center;
			messageLabel.Margin = new Thickness(DefaultMargin * 2, 0, DefaultMargin, 0);

			switchPanel.Children.Add(errorLabel);
			switchPanel.Children.Add(messageLabel);

			// argh, that **** calls us back when we change the state manually.
			var section = new Soft.Section();

			sw.Checked += (sender, args) =>
			{
				if (!section.IsLocked)
					context.requestAction(item, DominationAction.Dominate);
			};

			sw.Unchecked += (sender, args) =>
			{
				if (!section.IsLocked)
					context.requestAction(item, DominationAction.MakeSubmissive);
			};

			context.registerFeedback(item,
				state =>
				{
					bool error = state.Error_ != null;
					if (error)
					{
						errorLabel.Text = state.Error_.Message;
					}
					else
					{
						Debug.Assert(state.State_ != null);
						switch (state.State_.Value.Kind)
						{
						case DominatorStateKind.Dominated:
							using (section.Lock())
								sw.IsChecked = true;
							break;
						case DominatorStateKind.Submissive:
							using (section.Lock())
								sw.IsChecked = false;
							sw.UncheckedContent = L_YES;
							sw.UncheckedBackground = UncheckedBackgroundRed;
						break;
						case DominatorStateKind.Indetermined:
							using (section.Lock())
								sw.IsChecked = false;
							sw.UncheckedContent = L_N_A;
							sw.UncheckedBackground = UncheckedBackgroundOrange;
						break;
						}

						messageLabel.Text = state.State_.Value.Message;
					}

					errorLabel.Visibility = error ? Visibility.Visible : Visibility.Collapsed;
					messageLabel.Visibility = error ? Visibility.Collapsed : Visibility.Visible;
				});

			panel.Children.Add(switchPanel);
			return panel;
		}
示例#3
0
		public static UIElement ForDominator(IDominator dominator, IUIRegistrationContext registrationContext)
		{
			return dominator.DispatchTo(group => ForGroup(group, registrationContext), item => ForItem(item, registrationContext));
		}