/src/server/gwtgui/src/keymind/keywatch/gui/client/desktop/TabItemWidget.java
http://keywatch.googlecode.com/ · Java · 179 lines · 107 code · 18 blank · 54 comment · 16 complexity · dc4c5d50d308cf475c45c9176f2a66a6 MD5 · raw file
- /**
- * -----------------------------------------------------------------------------------------------
- * File: TabItemWidget.java
- *
- * Copyright (c) 2007 by Keymind Computing as.
- * All rights reserved.
- *
- * This file is subject to the terms and conditions of the Apache Licence 2.0.
- * See the file LICENCE in the main directory of the Keywatch distribution for more details.
- *
- * Revision History:
- * $URL: http://keywatch.googlecode.com/svn/trunk/src/server/gwtgui/src/keymind/keywatch/gui/client/desktop/TabItemWidget.java $
- * $Date: 2009-09-17 11:14:51 +0200 (Thu, 17 Sep 2009) $, $Rev: $
- * -----------------------------------------------------------------------------------------------
- */
- package keymind.keywatch.gui.client.desktop;
-
- import com.google.gwt.event.dom.client.ClickEvent;
- import com.google.gwt.event.dom.client.ClickHandler;
- import com.google.gwt.event.logical.shared.CloseHandler;
- import com.google.gwt.event.logical.shared.CloseEvent;
- import com.google.gwt.user.client.Window;
- import com.google.gwt.user.client.ui.*;
- import keymind.keywatch.gui.client.util.Constants;
-
- /**
- * Displays a label and close button. Each desktop tab contains an instance.
- */
- public class TabItemWidget extends Composite implements ClickHandler
- {
- private DesktopPanel desktopPanel;
- private Label label;
- private Image close;
- private InputBox inputBox;
-
- static final String PROMPT_TITLE_RENAME = "Rename";
- static final String PROMPT_RENAME = "Please specify the new desktop name.";
- static final String PROMPT_REMOVE = "Are you sure you want to remove the current desktop tab from you profile?";
- static final String TABNAME_SETTINGS = "Settings";
- static final String RENAME_NOT_UNIQUE = "Could not rename because another desktop with the same name exists";
-
- /**
- * C'tor
- * @param text Text to display
- * @param desktopPanel Owning desktop panel.
- */
- public TabItemWidget(String text, DesktopPanel desktopPanel)
- {
- this.desktopPanel = desktopPanel;
-
- FlexTable table = new FlexTable();
-
- label = new Label(text);
- label.setWidth(Constants.MAX_PERCENT);
- label.addClickHandler(this);
-
- Label space = new Label();
- space.setWidth("5px");
-
- close = GUICtrl.getCoreImageBundle().view_close_black().createImage();
- close.addClickHandler(this);
-
- // Initialize, the close image is not visible. The desktop framework will change
- // visibility as needed.
- close.setVisible(false);
-
- table.setWidget(0,0, label);
- table.setWidget(0,1, space);
- table.setWidget(0,2, close);
-
- initWidget(table);
- }
-
- /**
- * Show or hide close button
- *
- * @param visible If true, show close button, else hide it
- */
- public void setCloseVisible(boolean visible)
- {
- close.setVisible(visible);
- }
-
- /**
- * Called when the Close button is pressed. We call back to the owning DesktopPanel
- * to do the actual closing.
- *
- * @param evt Widget that was clicked
- */
- public void onClick(ClickEvent evt)
- {
- if(evt.getSource() == close)
- {
- closeDesktop();
- }
- else
- {
- if(GUICtrl.getAppDesktop().getCurrentDesktop() == desktopPanel &&
- !desktopPanel.isSettingsDesktop())
- {
- renameDesktop();
- }
- }
- }
-
- /**
- * Rename the desktop
- */
- private void renameDesktop()
- {
- // Ask for new name
- inputBox = new InputBox(PROMPT_TITLE_RENAME, PROMPT_RENAME);
- inputBox.setInputText(desktopPanel.getCategory().getName());
- inputBox.addCloseHandler(new CloseHandler<PopupPanel>()
- {
- public void onClose(CloseEvent<PopupPanel> event)
- {
- popupClosed(event.getTarget(), event.isAutoClosed());
- }
- });
-
- // Center and show dialog
- GUICtrl.showDialog(inputBox);
- }
-
- /**
- * A popup window was closed
- *
- * @param popupPanel The window that was closed
- * @param autoClosed True if the popup was closed by clicking outside the control
- */
- public void popupClosed(PopupPanel popupPanel, boolean autoClosed)
- {
- if(popupPanel == inputBox)
- {
- if (!autoClosed && inputBox.isOkClicked())
- {
- String name = inputBox.getInputText();
- if (name != null && name.length() > 0 && !name.equals(TABNAME_SETTINGS))
- {
- // The name must be unique
- if (GUICtrl.getProfileManager().getCategoryByName(name) == null)
- {
- desktopPanel.getCategory().setName(name);
- //GUICtrl.getAppDesktop().renameActiveDesktop(name);
- label.setText(name);
-
- // Save immediately
- GUICtrl.getProfileManager().setDirty(true);
- GUICtrl.getProfileManager().updateProfile(false);
- }
- else
- {
- Window.alert(RENAME_NOT_UNIQUE);
- }
- }
- }
- }
- }
-
- /**
- * Close the desktop
- */
- private void closeDesktop()
- {
- if(!desktopPanel.isSettingsDesktop())
- {
- if (Window.confirm(PROMPT_REMOVE))
- {
- // Remove the desktop
- GUICtrl.getAppDesktop().removeDesktop(desktopPanel);
- }
- }
- else
- {
- GUICtrl.getAppDesktop().hideSettingsDesktop();
- }
- }
- }