/*
 * Copyright 2014 JBoss by Red Hat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jbpm.console.ng.ht.forms.client.editors.taskform.displayers.util;

import com.google.gwt.user.client.ui.HasWidgets;
import java.util.Map;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import java.util.HashMap;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.client.mvp.PlaceStatus;
import org.uberfire.mvp.impl.DefaultPlaceRequest;

/**
 * @author pefernan
 */
@Dependent
public class PlaceManagerFormActivitySearcher {

    @Inject
    private PlaceManager placeManager;


    public void findFormActivityWidget( String name,
                                            Map<String, String> params, HasWidgets widget ) {

        if(params == null){
            params = new HashMap<String, String>();
        }
        DefaultPlaceRequest defaultPlaceRequest = new DefaultPlaceRequest(name + " Form", params);
        widget.clear();
        PlaceStatus status = placeManager.getStatus(defaultPlaceRequest);
        if(status.equals(PlaceStatus.OPEN)){
            placeManager.closePlace(defaultPlaceRequest);
            placeManager.forceClosePlace(defaultPlaceRequest);
        }
        placeManager.goTo(defaultPlaceRequest, widget);

    }

}

@@ -685,48 +685,59 @@
 ort 
-com.google.gwt.user.client.ui.HasWidgets
+java.util.HashMap;%0Aimport java.util.IdentityHashMap
 ;%0Aim
@@ -752,24 +752,25 @@
 a.util.Map;%0A
+%0A
 import javax
@@ -833,34 +833,8 @@
 t;%0A%0A
-import java.util.HashMap;%0A
 impo
@@ -918,16 +918,49 @@
 Status;%0A
+import org.uberfire.debug.Debug;%0A
 import o
@@ -1006,94 +1006,354 @@
 t;%0A%0A
-/**%0A * @author pefernan%0A */%0A@Dependent%0Apublic class PlaceManagerFormActivitySearcher %7B
+import com.google.gwt.event.logical.shared.AttachEvent;%0Aimport com.google.gwt.user.client.ui.HasWidgets;%0Aimport com.google.gwt.user.client.ui.Panel;%0A%0A/**%0A * @author pefernan%0A */%0A@Dependent%0Apublic class PlaceManagerFormActivitySearcher %7B%0A%0A    private static IdentityHashMap%3CPanel, Integer%3E customContainers = new IdentityHashMap%3CPanel, Integer%3E();
 %0A%0A  
@@ -1739,16 +1739,934 @@
 params);
+%0A%0A        final Panel container = (Panel) widget;%0A        if ( customContainers.get( container ) == null ) %7B%0A%0A            System.out.println(%22Got new custom container %22 + Debug.objectId( widget ));%0A            container.getElement().addClassName( %22custom-container-%22 + Debug.toMemorableString( System.identityHashCode( widget ) ) + %22-%22 + customContainers.size() );%0A            customContainers.put( container, customContainers.size() );%0A            container.addAttachHandler( new AttachEvent.Handler() %7B%0A                @Override%0A                public void onAttachOrDetach( AttachEvent event ) %7B%0A                    new Exception( %22Container attached %22 + event.isAttached() + %22: %22 + container.getElement().getId()).printStackTrace(System.out);%0A                %7D%0A            %7D );%0A        %7D else %7B%0A            System.out.println(%22Reusing custom container %22 + container.getElement().getAttribute( %22class%22 ));%0A        %7D
 %0A       

Debug logging to help diagnose the blank custom panel issue (not part of the fix)