View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.client.rep.controller;
19  
20  import org.vectomatic.client.rep.view.DrawingView;
21  
22  import com.google.gwt.user.client.Command;
23  import com.google.gwt.user.client.ui.MenuItem;
24  
25  /**
26   * Menu item customized to support enable/disable state
27   * and call invocation of a Controller
28   */
29  public class ControllerMenuItem extends MenuItem implements Command {
30  	private IController _controller;
31  	private boolean _enabled;
32  	private DrawingView _view;
33  	public ControllerMenuItem(DrawingView view, String text, IController controller) {
34  		super(text, (Command)null);
35  		setCommand(this);
36  		_view = view;
37  		_controller = controller;
38  		_enabled = true;
39  	}
40  	public void execute() {
41  		if (_enabled) {
42  			_controller.activate(_view);
43  		}
44  	}
45  	public boolean isEnabled() {
46  		return _enabled;
47  	}
48  	public void setEnabled(boolean enabled) {
49  		if (_enabled != enabled) {
50  			_enabled = enabled;
51  			if (enabled) {
52  				removeStyleName("gwt-MenuItem-disabled");				
53  			} else {
54  				addStyleName("gwt-MenuItem-disabled");
55  			}
56  		}
57  	}
58  }