Example usage for com.google.gwt.user.client.ui Widget asWidgetOrNull

List of usage examples for com.google.gwt.user.client.ui Widget asWidgetOrNull

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget asWidgetOrNull.

Prototype

public static Widget asWidgetOrNull(IsWidget w) 

Source Link

Document

This convenience method makes a null-safe call to IsWidget#asWidget() .

Usage

From source file:org.codesearch.indexer.client.ui.RootContainer.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from ww w  . j av a  2s  . co  m*/
public void setWidget(IsWidget w) {
    contentPanel.clear();
    Widget widget = Widget.asWidgetOrNull(w);
    if (widget != null) {
        contentPanel.add(w);
    }
}

From source file:org.nsesa.editor.gwt.editor.client.Editor.java

License:EUPL

/**
 * Initialize the main UI component(s) and add them to the {@link RootLayoutPanel}.
 * We're currently also setting up the {@link ActivityManager} and {@link EditorPlaceFactory}, but they are
 * unused until we handle multiple document controllers.
 */// ww  w. ja  v  a  2  s.  c o m
protected void initializeUI() {

    // set up the main window
    final EditorController editorController = getInjector().getEditorController();
    editorController.registerListeners();
    // there seems to be no other way to inject this 'injector'
    editorController.setInjector(getInjector());

    PlaceController placeController = clientFactory.getPlaceController();
    EventBus eventBus = clientFactory.getEventBus();

    final ActivityManager activityManager = getActivityManager(eventBus);
    activityManager.setDisplay(new AcceptsOneWidget() {
        @Override
        public void setWidget(IsWidget activityWidget) {
            Widget widget = Widget.asWidgetOrNull(activityWidget);
            appWidget.setVisible(widget != null);
            appWidget.setWidget(widget);
        }
    });

    // install keyboard listener
    clientFactory.getKeyboardListener().install();

    RootLayoutPanel.get().add(appWidget);

    final EditorPlaceFactory placeFactory = getInjector().getPlaceFactory();
    // Start PlaceHistoryHandler with our PlaceHistoryMapper
    final EditorPlaceHistoryMapper historyMapper = GWT.create(EditorPlaceHistoryMapper.class);
    historyMapper.setFactory(placeFactory);
    Place defaultPlace = placeFactory.getDefaultPlace();
    PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
    historyHandler.register(placeController, eventBus, defaultPlace);

    // Goes to the place represented on URL else default place
    historyHandler.handleCurrentHistory();
}

From source file:org.qipki.clients.web.client.ui.widgets.SidebarPanel.java

License:Open Source License

@Override
public void setWidget(IsWidget w) {
    final Widget widget = Widget.asWidgetOrNull(w);
    if (widget != getWidget()) {
        setHorizontalScrollPosition(0);//from  ww  w  .  j  a v a2 s .c o m
        setVerticalScrollPosition(0);
        boolean oldWidget = getWidget() != null;
        boolean newWidget = widget != null;
        if (oldWidget && newWidget) {
            // Replace
            //Window.alert( "replace" );
            setWidget(widget);
            mainLayout.setSidebarActivated(this, true, false, null);
        } else if (oldWidget) {
            // Hide
            //Window.alert( "hide" );
            setWidget(widget); // FIXME This statement should be in the animation complete callback
            mainLayout.setSidebarActivated(this, false, true, new AnimationCallback() {

                @Override
                public void onAnimationComplete() {
                }

                @Override
                public void onLayout(Layer layer, double progress) {
                }

            });
        } else if (newWidget) {
            // Show
            //Window.alert( "show" );
            setWidget(widget);
            mainLayout.setSidebarActivated(this, true, true, null);
        } else {
            // Should not happen
            Window.alert(
                    "SidebarPanel\n\n!oldWidget && !newWidget\nThis should not happen\n\nExpect bad layout behaviour!");
        }
    }
}

From source file:org.seamless.gwt.component.client.widget.SimpleLayoutPanel.java

License:Open Source License

@Override
public void setWidget(IsWidget w) {
    this.clear();
    Widget widget = Widget.asWidgetOrNull(w);
    if (widget != null) {
        this.add(widget);
    }/*  ww  w .j  a v a2 s.c o m*/
}

From source file:org.sigmah.client.ui.presenter.admin.models.base.AbstractModelsAdminPresenter.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww  w .ja v a 2  s  . c o m*/
 */
@Override
public void onBind() {

    // --
    // Grid selection change event.
    // --

    view.getGrid().getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<E>() {

        @Override
        public void selectionChanged(final SelectionChangedEvent<E> event) {
            final boolean singleItemSelected = event.getSelection() != null && event.getSelection().size() == 1;
            view.getGridDeleteButton().setEnabled(singleItemSelected);
            view.getGridExportButton().setEnabled(singleItemSelected);
            view.getGridDuplicateButton().setEnabled(singleItemSelected);
        }
    });

    // --
    // Grid events handler implementation.
    // --

    view.setGridEventHandler(new GridEventHandler<E>() {

        @Override
        public void onRowClickEvent(final E model) {

            // Selects the row.
            view.getGrid().getSelectionModel().select(model, false);

            // Loads the corresponding model.
            loadModel(model.getId());
        }
    });

    // --
    // Add button handler.
    // --

    view.getGridAddButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(final ButtonEvent event) {
            eventBus.navigate(getAddModelPage(), view.getGridAddButton());
        }
    });

    // --
    // Import button handler.
    // --

    view.getGridImportButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(final ButtonEvent event) {
            eventBus.navigateRequest(Page.IMPORT_MODEL.requestWith(RequestParameter.TYPE, getModelToImport()));
        }

    });

    // --
    // Delete button handler.
    // --

    view.getGridDeleteButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(final ButtonEvent event) {
            onDeleteAction(view.getGrid().getSelectionModel().getSelectedItem());
        }
    });

    // --
    // Export button handler.
    // --

    view.getGridExportButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(final ButtonEvent event) {
            onExportAction(view.getGrid().getSelectionModel().getSelectedItem());
        }
    });

    // --
    // Duplicate button handler.
    // --

    view.getGridDuplicateButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(final ButtonEvent event) {
            onDuplicateAction(view.getGrid().getSelectionModel().getSelectedItem());
        }
    });

    // --
    // Close button handler.
    // --

    view.getDetailsCloseButton().addSelectionListener(new SelectionListener<IconButtonEvent>() {

        @Override
        public void componentSelected(final IconButtonEvent event) {
            loadModel(null);
        }
    });

    // --
    // Save header form button handler.
    // --

    view.getHeaderSaveButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(final ButtonEvent event) {

            if (!view.getHeaderForm().isValid()) {
                return;
            }

            onSaveAction(currentModel, new AsyncCallback<E>() {

                @Override
                public void onFailure(final Throwable caught) {
                    // Does nothing, error message is already handled by child presenters.
                }

                @Override
                public void onSuccess(final E updatedModel) {

                    // Updates the current model.
                    updateModel(updatedModel);
                    view.getStore().update(updatedModel);

                    // Updates the model status.
                    loadStatus(updatedModel.getStatus());

                    // Updates tab view content.
                    currentTabPresenter.loadTab(updatedModel);
                }
            });
        }
    });

    // --
    // Save header status field change event handler.
    // --

    view.getHeaderStatusField().addListener(Events.Select, new Listener<FieldEvent>() {

        @Override
        public void handleEvent(final FieldEvent event) {

            final ProjectModelStatus currentStatus = currentModel.getStatus();
            final ProjectModelStatus targetStatus = EnumModel.getEnum(view.getHeaderStatusField().getValue());

            if (targetStatus == null) {
                return;
            }

            final AsyncCallback<Void> callback = new AsyncCallback<Void>() {

                @Override
                public void onFailure(Throwable caught) {
                    view.getHeaderStatusField().setValue(new EnumModel<ProjectModelStatus>(currentStatus));
                }

                @Override
                public void onSuccess(Void result) {
                    // Select event is allowed, nothing to do.
                }
            };

            if (currentStatus != ProjectModelStatus.UNAVAILABLE) {

                final Pair<Boolean, String> validation = ProjectModelStatus.isValidStatusChange(currentStatus,
                        targetStatus);

                if (ClientUtils.isNotTrue(validation.left)) {
                    // Invalid status change.
                    N10N.warn(I18N.CONSTANTS.error(), validation.right);
                    callback.onFailure(null);
                    return;
                }
            }

            onStatusChangeEvent(currentModel.getId(), currentStatus, targetStatus, callback);
        }
    });

    // --
    // Tabs initialization.
    // --

    for (final IsModelTabPresenter<E, ?> tabPresenter : tabPresenters) {

        tabPresenter.initialize(); // CRUCIAL!

        view.addTab(tabPresenter.getTabTitle(), Widget.asWidgetOrNull(tabPresenter.getView()),
                new Listener<ComponentEvent>() {

                    @Override
                    public void handleEvent(final ComponentEvent event) {
                        currentTabPresenter = tabPresenter;
                        tabPresenter.loadTab(currentModel);
                    }
                });
    }

    // Handler

    registerHandler(eventBus.addHandler(UpdateEvent.getType(), new UpdateHandler() {

        @Override
        public void onUpdate(final UpdateEvent event) {

            if (event.concern(getUpdateEventKey())) {
                // Model update event.
                final E createdModel = event.getParam(0);

                if (createdModel == null) {
                    return;
                }

                view.getStore().add(createdModel);
                view.getStore().commitChanges();
                view.getStore().applyFilters(null);
                view.getGrid().getSelectionModel().select(createdModel, false);

            } else if (event.concern(UpdateEvent.LAYOUT_GROUP_UPDATE)) {
                // Layout group update event.
                loadModel(currentModel.getId()); // Reloads the entire model and updates the view.

            } else if (event.concern(UpdateEvent.FLEXIBLE_ELEMENT_UPDATE)
                    && event.getParam(0) instanceof IsModel) {
                // Flexible element (field) update event.
                final E updatedModel = event.getParam(0);
                updateModel(updatedModel);

            } else if (event.concern(UpdateEvent.PROJECT_MODEL_IMPORT)
                    || event.concern(UpdateEvent.ORG_UNIT_MODEL_IMPORT)) {
                // Import update event.
                loadModels();
            }
        }
    }));

    // --
    // Maintenance fields.
    // --

    view.getUnderMaintenanceField().addListener(Events.Change, new Listener<FieldEvent>() {

        @Override
        public void handleEvent(FieldEvent be) {
            final boolean underMaintenance = view.getUnderMaintenanceField().getValue() != null
                    && view.getUnderMaintenanceField().getValue();

            view.getMaintenanceDateField().setVisible(underMaintenance);
            view.getMaintenanceTimeField().setVisible(underMaintenance);
            view.getHeaderStatusField().setEnabled(!underMaintenance);

            if (underMaintenance) {
                view.getMaintenanceGrid().setText(0, 1, I18N.CONSTANTS.maintenanceScheduleFrom());
                view.getMaintenanceGrid().setText(0, 3, I18N.CONSTANTS.maintenanceScheduleAt());

                final Date thirtyMinutesAfter = new Date(new Date().getTime() + 1000 * 60 * 30);
                view.getMaintenanceDateField().setValue(thirtyMinutesAfter);
                view.getMaintenanceTimeField()
                        .setValue(((TimeField) view.getMaintenanceTimeField()).findModel(thirtyMinutesAfter));

            } else {
                view.getMaintenanceGrid().clearCell(0, 1);
                view.getMaintenanceGrid().clearCell(0, 3);
            }
        }
    });
}

From source file:org.sigmah.client.ui.presenter.base.AbstractPresenter.java

License:Open Source License

/**
 * {@inheritDoc}/*w w  w .j  a va2s  . co  m*/
 */
@Override
public void revealView() {

    if (Log.isTraceEnabled()) {
        Log.trace("Reveals '" + view.getClass().getName() + "' presenter's view.");
    }

    if (isSubPresenter()) {
        // Presenter's view is shown into parent presenter's placeholder.
        final HasSubPresenter<? extends HasSubView> parentPresenter = ((SubPresenter<?>) this)
                .getParentPresenter();
        final LayoutContainer placeHolder = parentPresenter.getView().getPlaceHolder();

        placeHolder.removeAll();
        placeHolder.add(Widget.asWidgetOrNull(getView()));

        injector.getApplicationPresenter().showPresenter(parentPresenter);

        placeHolder.layout();

    } else {
        // Presenter's view is shown into application's main view.
        injector.getApplicationPresenter().showPresenter(this);
    }

    view.onViewRevealed();
    onViewRevealed();
}

From source file:org.sigmah.client.ui.view.base.AbstractView.java

License:Open Source License

/**
 * Adds the given {@code widget} into the parent layout.
 * //from  w ww .j  a  v  a2 s  .  c  om
 * @param widget
 *          The widget to add.
 * @param layoutData
 *          The layout data. If {@code null}, default center layout data is set.
 * @see com.extjs.gxt.ui.client.widget.layout.BorderLayoutData
 */
protected final void add(final IsWidget widget, BorderLayoutData layoutData) {

    if (layoutData == null) {
        layoutData = Layouts.borderLayoutData(LayoutRegion.CENTER);
    }

    this.layoutContainer.add(Widget.asWidgetOrNull(widget), layoutData);
}

From source file:org.sigmah.client.ui.widget.form.Forms.java

License:Open Source License

/**
 * Wraps the given {@code widget} with a ScollPanel and builds an 
 * {@link AdapterField} for it.// w ww.j  av a2s. c  o  m
 * 
 * @param label
 *         The field label. If {@code blank}, label separator is automatically disabled.
 * @param widget
 *         The widget wrapped into the scroll panel and into the adapter field.
 * @param width
 *         Width of the given widget.
 * @param height
 *         Height of the scroll panel.
 * @return The field.
 */
public static AdapterField adapterWithScrollbars(final String label, final IsWidget widget, final int width,
        final int height) {

    final ScrollPanel scrollPanel = new ScrollPanel();
    scrollPanel.setWidget(Widget.asWidgetOrNull(widget));
    scrollPanel.addAttachHandler(new AttachEvent.Handler() {
        @Override
        public void onAttachOrDetach(AttachEvent event) {
            scrollPanel.setWidth(width + "px");
        }
    });
    scrollPanel.setHeight(height + "px");

    return adapter(label, scrollPanel);

}

From source file:org.sigmah.client.ui.widget.form.Forms.java

License:Open Source License

/**
 * Builds an {@link AdapterField} for the given {@code widget}.
 * //  www.  j a  v a2 s  . co m
 * @param label
 *          The field label. If {@code blank}, label separator is automatically disabled.
 * @param widget
 *          The widget wrapped into the adapter field.
 * @param resizeWidget
 *          {@code true} to resize the widget.
 * @return The field.
 */
public static AdapterField adapter(final String label, final IsWidget widget, final Boolean resizeWidget) {

    final AdapterField field = new AdapterField(Widget.asWidgetOrNull(widget));

    // Label.
    if (ClientUtils.isNotBlank(label)) {
        field.setFieldLabel(label);
    } else {
        field.setLabelSeparator("");
    }

    // Resize widget?
    if (resizeWidget != null) {
        field.setResizeWidget(resizeWidget.booleanValue());
    }

    return field;

}

From source file:ru.fly.client.ui.panel.SingleLayout.java

License:Apache License

@Override
public void setWidget(IsWidget w) {
    setWidget(Widget.asWidgetOrNull(w));
}