Fixed hide window
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-sdmx-import-widget@84400 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4d890c191a
commit
ae08b022fd
|
@ -8,7 +8,6 @@ import java.util.ArrayList;
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.TRId;
|
||||
import org.gcube.portlets.user.td.sdmximportwidget.client.util.ErrorMessageBox;
|
||||
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.core.client.Callback;
|
||||
import com.google.gwt.user.client.Command;
|
||||
|
@ -28,15 +27,17 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class WizardWindow extends Window {
|
||||
|
||||
protected final String WIZARDWIDTH="640px";
|
||||
protected final String WIZARDHEIGHT="480px";
|
||||
protected final boolean WIZARRESIZABLE=false;
|
||||
protected final String WIZARDWIDTH = "640px";
|
||||
protected final String WIZARDHEIGHT = "480px";
|
||||
protected final boolean WIZARRESIZABLE = false;
|
||||
protected final boolean WIZARDCOLLAPSIBLE = true;
|
||||
|
||||
|
||||
protected ArrayList<WizardCard> cardStack = new ArrayList<WizardCard>();
|
||||
|
||||
|
@ -62,19 +63,19 @@ public class WizardWindow extends Window {
|
|||
|
||||
/**
|
||||
* Create a new Wizard Window with the specified title.
|
||||
* @param title the wizard window title.
|
||||
*
|
||||
* @param title
|
||||
* the wizard window title.
|
||||
*/
|
||||
public WizardWindow(String title)
|
||||
{
|
||||
public WizardWindow(String title) {
|
||||
super();
|
||||
this.eventBus= new SimpleEventBus();
|
||||
this.eventBus = new SimpleEventBus();
|
||||
Log.info(title);
|
||||
setResizable(WIZARRESIZABLE);
|
||||
setCollapsible(false);
|
||||
setCollapsible(WIZARDCOLLAPSIBLE);
|
||||
setWidth(WIZARDWIDTH);
|
||||
setHeight(WIZARDHEIGHT);
|
||||
|
||||
|
||||
listeners = new ArrayList<WizardListener>();
|
||||
|
||||
setHeadingText(title);
|
||||
|
@ -105,17 +106,21 @@ public class WizardWindow extends Window {
|
|||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
TextButton button = (TextButton)event.getSource();
|
||||
TextButton button = (TextButton) event.getSource();
|
||||
String btnID = button.getId();
|
||||
|
||||
if (btnID.equals(backButton.getId())) {
|
||||
|
||||
if(previousButtonAction!=null) previousButtonAction.execute();
|
||||
else previousCard();
|
||||
if (previousButtonAction != null)
|
||||
previousButtonAction.execute();
|
||||
else
|
||||
previousCard();
|
||||
} else {
|
||||
|
||||
if (nextButtonAction!=null) nextButtonAction.execute();
|
||||
else nextCard();
|
||||
if (nextButtonAction != null)
|
||||
nextButtonAction.execute();
|
||||
else
|
||||
nextCard();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -124,21 +129,9 @@ public class WizardWindow extends Window {
|
|||
backButton.addSelectHandler(selectionHandler);
|
||||
nextButton.addSelectHandler(selectionHandler);
|
||||
|
||||
closeBtnHandle();
|
||||
setWidget(container);
|
||||
}
|
||||
|
||||
protected void closeBtnHandle() {
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
fireAborted();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -146,121 +139,110 @@ public class WizardWindow extends Window {
|
|||
protected void initTools() {
|
||||
super.initTools();
|
||||
|
||||
//we can't distinguish between hide and hide with button
|
||||
/*closeBtn.removeAllListeners();
|
||||
closeBtn.addListener(Events.Select, new Listener<ComponentEvent>() {
|
||||
public void handleEvent(ComponentEvent ce) {
|
||||
MessageBox.confirm("Confirm", "Are you sure to cancel the operation?", new Listener<MessageBoxEvent>() {
|
||||
closeBtn.addSelectHandler(new SelectHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelect(SelectEvent event) {
|
||||
fireAborted();
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void handleEvent(MessageBoxEvent be) {
|
||||
if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
|
||||
hide();
|
||||
fireAborted();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
public void addListener(WizardListener listener)
|
||||
{
|
||||
public void addListener(WizardListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(WizardListener listener)
|
||||
{
|
||||
public void removeListener(WizardListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the next available card.
|
||||
*/
|
||||
public void nextCard()
|
||||
{
|
||||
public void nextCard() {
|
||||
|
||||
Widget activeItem = cardContainer.getActiveWidget();
|
||||
|
||||
if (activeItem instanceof WizardCard) ((WizardCard)activeItem).dispose();
|
||||
if (activeItem instanceof WizardCard)
|
||||
((WizardCard) activeItem).dispose();
|
||||
|
||||
int cardPos = cardStack.indexOf(activeItem);
|
||||
|
||||
//NEXT ->
|
||||
// NEXT ->
|
||||
|
||||
nextButton.setEnabled(true);
|
||||
backButton.setEnabled(true);
|
||||
|
||||
int newPos=cardPos+1;
|
||||
int newPos = cardPos + 1;
|
||||
|
||||
if (newPos == 0) {
|
||||
//we are moving forward from the first card
|
||||
// we are moving forward from the first card
|
||||
backButton.setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
nextButtonAction=null;
|
||||
previousButtonAction=null;
|
||||
Log.info("cardStack size:"+cardStack.size());
|
||||
nextButtonAction = null;
|
||||
previousButtonAction = null;
|
||||
Log.info("cardStack size:" + cardStack.size());
|
||||
WizardCard card = cardStack.get(newPos);
|
||||
cardContainer.setActiveWidget(card);
|
||||
doLayout();
|
||||
if (card instanceof WizardCard) ((WizardCard)card).setup();
|
||||
if (card instanceof WizardCard)
|
||||
((WizardCard) card).setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the previous available card.
|
||||
*/
|
||||
public void previousCard()
|
||||
{
|
||||
public void previousCard() {
|
||||
Widget activeItem = cardContainer.getActiveWidget();
|
||||
|
||||
if (activeItem instanceof WizardCard) ((WizardCard)activeItem).dispose();
|
||||
if (activeItem instanceof WizardCard)
|
||||
((WizardCard) activeItem).dispose();
|
||||
|
||||
int cardPos = cardStack.indexOf(activeItem);
|
||||
|
||||
//BACK <-
|
||||
// BACK <-
|
||||
|
||||
nextButton.setEnabled(true);
|
||||
backButton.setEnabled(true);
|
||||
|
||||
int newPos=cardPos-1;
|
||||
|
||||
int newPos = cardPos - 1;
|
||||
|
||||
if (newPos == 0) {
|
||||
backButton.setEnabled(false);
|
||||
}
|
||||
|
||||
nextButtonAction=null;
|
||||
previousButtonAction=null;
|
||||
nextButtonAction = null;
|
||||
previousButtonAction = null;
|
||||
|
||||
WizardCard card = cardStack.get(newPos);
|
||||
cardContainer.setActiveWidget(card);
|
||||
doLayout();
|
||||
if (card instanceof WizardCard) ((WizardCard)card).setup();
|
||||
if (card instanceof WizardCard)
|
||||
((WizardCard) card).setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of available cards.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getCardStackSize()
|
||||
{
|
||||
public int getCardStackSize() {
|
||||
return cardStack.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current active card.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getCurrentCard()
|
||||
{
|
||||
public int getCurrentCard() {
|
||||
return cardStack.indexOf(cardContainer.getActiveWidget());
|
||||
}
|
||||
|
||||
public boolean checkBeforeClose()
|
||||
{
|
||||
public boolean checkBeforeClose() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -270,10 +252,10 @@ public class WizardWindow extends Window {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the label of next button to "Finish" value and add a close command to it.
|
||||
* Sets the label of next button to "Finish" value and add a close command
|
||||
* to it.
|
||||
*/
|
||||
public void setNextButtonToFinish()
|
||||
{
|
||||
public void setNextButtonToFinish() {
|
||||
nextButton.setText("Finish");
|
||||
nextButtonAction = new Command() {
|
||||
|
||||
|
@ -285,20 +267,21 @@ public class WizardWindow extends Window {
|
|||
|
||||
/**
|
||||
* Set the command for the next button.
|
||||
* @param command the command to execute.
|
||||
*
|
||||
* @param command
|
||||
* the command to execute.
|
||||
*/
|
||||
public void setNextButtonCommand(Command command)
|
||||
{
|
||||
public void setNextButtonCommand(Command command) {
|
||||
nextButtonAction = command;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the command for the previous button.
|
||||
* @param command the command to execute.
|
||||
*
|
||||
* @param command
|
||||
* the command to execute.
|
||||
*/
|
||||
public void setPreviousButtonCommand(Command command)
|
||||
{
|
||||
public void setPreviousButtonCommand(Command command) {
|
||||
previousButtonAction = command;
|
||||
}
|
||||
|
||||
|
@ -311,28 +294,28 @@ public class WizardWindow extends Window {
|
|||
|
||||
Widget activeItem = cardContainer.getActiveWidget();
|
||||
|
||||
if (activeItem instanceof WizardCard) ((WizardCard)activeItem).setup();
|
||||
if (activeItem instanceof WizardCard)
|
||||
((WizardCard) activeItem).setup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the card list.
|
||||
*
|
||||
* @param cards
|
||||
*/
|
||||
public void setCards(ArrayList<WizardCard> cards)
|
||||
{
|
||||
for (WizardCard card:cards) {
|
||||
public void setCards(ArrayList<WizardCard> cards) {
|
||||
for (WizardCard card : cards) {
|
||||
addCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a card to this wizard.
|
||||
* @param card the card to add.
|
||||
*
|
||||
* @param card
|
||||
* the card to add.
|
||||
*/
|
||||
public void addCard(WizardCard card)
|
||||
{
|
||||
public void addCard(WizardCard card) {
|
||||
card.setWizardWindow(this);
|
||||
cardContainer.add(card);
|
||||
cardStack.add(card);
|
||||
|
@ -340,77 +323,83 @@ public class WizardWindow extends Window {
|
|||
|
||||
/**
|
||||
* Remove a card to this wizard.
|
||||
* @param card the card to add.
|
||||
*
|
||||
* @param card
|
||||
* the card to add.
|
||||
*/
|
||||
public void removeCard(WizardCard card)
|
||||
{
|
||||
public void removeCard(WizardCard card) {
|
||||
cardContainer.remove(card);
|
||||
cardStack.remove(card);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enables the next button on the wizard.
|
||||
* @param enable <code>true</code> to enable the next button, <code>false</code> otherwise.
|
||||
*
|
||||
* @param enable
|
||||
* <code>true</code> to enable the next button,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public void setEnableNextButton(boolean enable)
|
||||
{
|
||||
public void setEnableNextButton(boolean enable) {
|
||||
nextButton.setEnabled(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the back button on the wizard.
|
||||
* @param enable <code>true</code> to enable the back button, <code>false</code> otherwise.
|
||||
*
|
||||
* @param enable
|
||||
* <code>true</code> to enable the back button,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public void setEnableBackButton(boolean enable)
|
||||
{
|
||||
public void setEnableBackButton(boolean enable) {
|
||||
backButton.setEnabled(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the next button label.
|
||||
* @param text the button label.
|
||||
*
|
||||
* @param text
|
||||
* the button label.
|
||||
*/
|
||||
protected void setNextButtonText(String text)
|
||||
{
|
||||
protected void setNextButtonText(String text) {
|
||||
nextButton.setText(text);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the back button label.
|
||||
* @param text the button label.
|
||||
*
|
||||
* @param text
|
||||
* the button label.
|
||||
*/
|
||||
protected void setBackButtonText(String text)
|
||||
{
|
||||
protected void setBackButtonText(String text) {
|
||||
backButton.setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets visible next button.
|
||||
*
|
||||
* @param visible
|
||||
*/
|
||||
protected void setNextButtonVisible(boolean visible)
|
||||
{
|
||||
protected void setNextButtonVisible(boolean visible) {
|
||||
nextButton.setVisible(visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets visible back button.
|
||||
*
|
||||
* @param visible
|
||||
*/
|
||||
protected void setBackButtonVisible(boolean visible)
|
||||
{
|
||||
protected void setBackButtonVisible(boolean visible) {
|
||||
backButton.setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a listener to the next button.
|
||||
* @param listener the listener to add.
|
||||
*
|
||||
* @param listener
|
||||
* the listener to add.
|
||||
*/
|
||||
protected void addNextButtonListener(SelectHandler listener)
|
||||
{
|
||||
protected void addNextButtonListener(SelectHandler listener) {
|
||||
nextButton.addSelectHandler(listener);
|
||||
}
|
||||
|
||||
|
@ -423,41 +412,42 @@ public class WizardWindow extends Window {
|
|||
|
||||
/**
|
||||
* Returns the card list.
|
||||
*
|
||||
* @return teh card list.
|
||||
*/
|
||||
public ArrayList<WizardCard> getCardStack()
|
||||
{
|
||||
public ArrayList<WizardCard> getCardStack() {
|
||||
return cardStack;
|
||||
}
|
||||
|
||||
public void showErrorAndHide(String title, final String failureReason, final String failureDetails, final Throwable throwable)
|
||||
{
|
||||
ErrorMessageBox.showError(title, failureReason, failureDetails, new Callback<Dialog, Void>() {
|
||||
public void showErrorAndHide(String title, final String failureReason,
|
||||
final String failureDetails, final Throwable throwable) {
|
||||
ErrorMessageBox.showError(title, failureReason, failureDetails,
|
||||
new Callback<Dialog, Void>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Dialog result) {
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(Dialog result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Void reason) {
|
||||
hide();
|
||||
fireFailed(throwable, failureReason, failureDetails);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(Void reason) {
|
||||
hide();
|
||||
fireFailed(throwable, failureReason, failureDetails);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void fireCompleted(TRId id)
|
||||
{
|
||||
for (WizardListener listener:listeners) listener.completed(id);
|
||||
public void fireCompleted(TRId id) {
|
||||
for (WizardListener listener : listeners)
|
||||
listener.completed(id);
|
||||
}
|
||||
|
||||
public void fireAborted()
|
||||
{
|
||||
for (WizardListener listener:listeners) listener.aborted();
|
||||
public void fireAborted() {
|
||||
for (WizardListener listener : listeners)
|
||||
listener.aborted();
|
||||
}
|
||||
|
||||
public void fireFailed(Throwable throwable, String reason, String details)
|
||||
{
|
||||
for (WizardListener listener:listeners) listener.failed(throwable, reason, details);
|
||||
public void fireFailed(Throwable throwable, String reason, String details) {
|
||||
for (WizardListener listener : listeners)
|
||||
listener.failed(throwable, reason, details);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue