All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.as.console.client.shared.subsys.infinispan.DefaultCacheContainerWindow Maven / Gradle / Ivy

Go to download

Bundles the core AS7 console as a GWT module. Includes minor customizations to support extensions.

There is a newer version: 0.7.0.Final
Show newest version
/* 
 * JBoss, Home of Professional Open Source 
 * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved. 
 * See the copyright.txt in the distribution for a 
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use, 
 * modify, copy, or redistribute it subject to the terms and conditions 
 * of the GNU Lesser General Public License, v. 2.1. 
 * This program is distributed in the hope that it will be useful, but WITHOUT A 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details. 
 * You should have received a copy of the GNU Lesser General Public License, 
 * v.2.1 along with this distribution; if not, write to the Free Software 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 */
package org.jboss.as.console.client.shared.subsys.infinispan;

import com.google.gwt.user.client.ui.Widget;
import org.jboss.as.console.client.shared.dispatch.DispatchAsync;
import org.jboss.as.console.client.shared.subsys.infinispan.model.CacheContainer;
import org.jboss.as.console.client.shared.subsys.infinispan.model.DefaultCacheContainer;
import org.jboss.as.console.client.shared.viewframework.EntityPopupWindow;
import org.jboss.as.console.client.shared.viewframework.EntityToDmrBridge;
import org.jboss.as.console.client.shared.viewframework.FrameworkView;
import org.jboss.as.console.client.shared.viewframework.SingleEntityToDmrBridgeImpl;
import org.jboss.as.console.client.widgets.forms.ApplicationMetaData;
import org.jboss.ballroom.client.widgets.forms.ComboBoxItem;
import org.jboss.ballroom.client.widgets.forms.Form;
import org.jboss.ballroom.client.widgets.forms.FormAdapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author Stan Silvert [email protected] (C) 2011 Red Hat Inc.
 */
public class DefaultCacheContainerWindow extends EntityPopupWindow {

    private static final ComboBoxItem valueCombo = new ComboBoxItem("name", "Default Cache Container");
    private static final Form myForm = makeForm(valueCombo);
    private static final WindowView myView = new WindowView(myForm);
    
    public DefaultCacheContainerWindow(ApplicationMetaData propertyMetadata, DispatchAsync dispatcher) {
        super("Set Default Cache Container", myForm, null, 
                new SingleEntityToDmrBridgeImpl(propertyMetadata, DefaultCacheContainer.class, myView, dispatcher));
        myView.setBridge(bridge);
        this.bridge.loadEntities(null);
        setWidth("330");
        setHeight("180");
    }
    
    private static Form makeForm(ComboBoxItem valueCombo) {
        Form form = new Form(DefaultCacheContainer.class);
        form.setFields(valueCombo);
        return form;
    }
    
    public static void setChoices(Collection choices) {
        List names = new ArrayList(choices.size());
        
        for (CacheContainer container : choices) names.add(container.getName());
        
        valueCombo.setValueMap(names);
        
        valueCombo.setValue(((DefaultCacheContainer)myView.getBridge().getEntityList().get(0)).getName());
    }
    
    @Override
    protected void doCommand(FormAdapter form) {
        this.bridge.onSaveDetails(form.getUpdatedEntity(), form.getChangedValues());
    }

    private static class WindowView implements FrameworkView {
        private Form myForm;
        private EntityToDmrBridge bridge;
        
        WindowView(Form myForm) {
            this.myForm = myForm;
        }
        
        void setBridge(EntityToDmrBridge bridge) {
            this.bridge = bridge;
        }
        
        EntityToDmrBridge getBridge() {
            return this.bridge;
        }
        
        @Override
        public Widget asWidget() {
            return null;
        }

        @Override
        public void initialLoad() {
            // do nothing
        }

        @Override
        public void refresh() {
            DefaultCacheContainer entity = (DefaultCacheContainer)bridge.getEntityList().get(0);
            myForm.edit(entity);
        }

        @Override
        public void setEditingEnabled(boolean isEnabled) {
            // do nothing
        }
        
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy