/* * Copyright (c) 2006,2007 Declarative Engineering LLC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Declarative Engineering LLC * verson 1 which accompanies this distribution, and is available at * http://declarativeengineering.com/legal/DE_Developer_License_v1.txt */ package test.local.view.controller; import test.local.view.ProjectEditorView; import test.model.Project; import com.foundation.metadata.Attribute; import com.foundation.view.ControlDecoration; import com.foundation.view.IViewContext; import com.foundation.view.resource.ResourceReference; public class ProjectEditorViewController extends AbstractViewController { public static final Attribute PROJECT = registerAttribute(ProjectEditorViewController.class, "project"); private Runnable changeListener; /** * ProjectEditorViewController constructor. * @param context The context underwhich the view is being created. This context manages the threading, resources, and request handling for the view as well as ties together related views. * @param changeListener The optional listener called when changes are applied to the project. * @param project The edited project. */ public ProjectEditorViewController(IViewContext context, Runnable changeListener, Project project) { super(context); this.changeListener = changeListener; setProject((Project) getReflectionManager().createReflection(project)); }//ProjectEditorViewController()// /* (non-Javadoc) * @see com.foundation.controller.AbstractViewController#getViewClass() */ protected Class getViewClass() { return ProjectEditorView.class; }//getViewClass()// /** * Applies changes to the project. */ public void doApply() { synchronize(); getReflectionManager().synchronizeAll(); if(changeListener != null) { changeListener.run(); }//if// }//doApply()// /* (non-Javadoc) * @see test.local.view.controller.AbstractViewController#validate() */ public boolean validate() { boolean result = true; getDecorationManager().clearDecorations(null, null); if((getProject().getName() == null) || (getProject().getName().trim().length() == 0)) { getDecorationManager().addDecoration(getProject(), Project.NAME, new ControlDecoration(new ResourceReference("res://View/ProjectEditor/ErrorOverlay"), "Must provide a name.")); result = false; }//if// if((getProject().getProgress() == null) || (getProject().getProgress().intValue() < 0) || (getProject().getProgress().intValue() > 100)) { getDecorationManager().addDecoration(getProject(), Project.PROGRESS, new ControlDecoration(new ResourceReference("res://View/ProjectEditor/ErrorOverlay"), "Must be a number between (0..100).")); result = false; }//if// getDecorationManager().applyDecorationChanges(); return result; }//validate()// /** * Rejects changes to the project. */ public void doCancel() { synchronize(); getProject().reverseObjectChanges(); }//doCancel()// /** * Gets the project being edited. * @return The edited project. */ public Project getProject() { return (Project) getAttributeValue(PROJECT); }//getProject()// /** * Sets the project being edited. * @param project The edited project. */ private void setProject(Project project) { setAttributeValue(PROJECT, project); }//getProject()// }//ProjectEditorViewController//