/** * */ package org.gcube.portlets.widgets.wsexplorer.client.load; import java.util.ArrayList; import java.util.List; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants; import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerController; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import com.github.gwtbootstrap.client.ui.Modal; import com.github.gwtbootstrap.client.ui.ModalFooter; import com.github.gwtbootstrap.client.ui.event.HideEvent; import com.github.gwtbootstrap.client.ui.event.HideHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.ui.Button; /** * The Class WorkspaceExplorerLoadDialog. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Jun 29, 2015 * * */ public class WorkspaceExplorerLoadDialog extends Modal implements HasWorskpaceExplorerNotificationListener{ private Button openButton; private WorkspaceExplorerLoadDialog INSTANCE = this; private boolean isSelect = false; private String captionTxt; private ModalFooter footer = new ModalFooter(); private WorkspaceExplorerController controller = new WorkspaceExplorerController(); private List listeners = new ArrayList(); /** * Instantiates a new worspace navigator dialog. * * @param captionTxt sets the text inside the caption, if null sets "Workspace Explorer" * * Add {@link WorskpaceExplorerNotificationListener} to receive events */ public WorkspaceExplorerLoadDialog(String captionTxt) { this.captionTxt = (captionTxt==null || captionTxt.isEmpty())?WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION:captionTxt; // setText(this.captionTxt); setAnimation(false); setCloseVisible(true); setTitle(this.captionTxt); openButton = new Button("Open"); setWidth(710); // setHeight("650px"); setMaxHeigth("500px"); hide(false); addHideHandler(new HideHandler() { @Override public void onHide(HideEvent hideEvent) { if(!isSelect) notifyAborted(); } }); // DockPanel dock = new DockPanel(); // dock.setSpacing(5); // dock.add(okButton, DockPanel.SOUTH); // dock.add(cancel, DockPanel.SOUTH); // HorizontalPanel hp = new HorizontalPanel(); // hp.setStyleName("margin-auto"); ////// hp.add(okButton); //// hp.setWidth("50%"); //// hp.setStyleAttribute("margin", "0 auto"); // hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); // cancel.getElement().getStyle().setMarginTop(5.0, Unit.PX); //// cancel.getElement().getStyle().setMarginBottom(5.0, Unit.PX); //// hp.getElement().getStyle().setMarginLeft("0 auto", Unit.PCT); // hp.add(cancel); // dock.add(hp, DockPanel.SOUTH); // // dock.add(controller.getWorkspaceExplorerPanel(), DockPanel.CENTER); // // dock.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); // dock.setWidth("100%"); add(controller.getWorkspaceExplorerPanel()); // okButton.addClickHandler(new ClickHandler() { // // @Override // public void onClick(ClickEvent event) { // // } // }); openButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { isSelect = false; Item item = controller.getWsExplorer().getItemSelected(); if(item!=null){ isSelect = true; INSTANCE.hide(); notifySelectedItem(item); } } }); footer.add(openButton); add(footer); } /** * Notify selected item. * * @param selected the selected */ private void notifySelectedItem(Item selected){ for (WorskpaceExplorerNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onSelectedItem(selected); } } /** * Notify aborted. * * @param selected the selected */ private void notifyAborted(){ for (WorskpaceExplorerNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onAborted(); } } /** * Notify failed. * * @param t the t */ private void notifyFailed(Throwable t){ for (WorskpaceExplorerNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onFailed(t); } } /** * Gets the caption txt. * * @return the captionTxt */ public String getCaptionTxt() { return captionTxt; } /** * Checks if is valid hide. * * @return the isValidHide */ public boolean isValidHide() { return isSelect; } /* (non-Javadoc) * @see com.github.gwtbootstrap.client.ui.Modal#show() */ @Override public void show() { super.show(); isSelect = false; } /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener#addWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener) */ @Override public void addWorkspaceExplorerNotificationListener(WorskpaceExplorerNotificationListener handler) { if(handler!=null) listeners.add(handler); } /* (non-Javadoc) * @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener#removeWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener) */ @Override public void removeWorkspaceExplorerNotificationListener(WorskpaceExplorerNotificationListener handler) { if(handler!=null){ if(listeners.contains(handler)) listeners.remove(handler); } } }