Package org.drools.guvnor.client.asseteditor

Source Code of org.drools.guvnor.client.asseteditor.BusinessProcessEditor

/*
* Copyright 2010 JBoss Inc
*
* 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.drools.guvnor.client.asseteditor;

import org.drools.guvnor.client.common.DirtyableComposite;
import org.drools.guvnor.client.configurations.ApplicationPreferences;
import org.drools.guvnor.client.explorer.ClientFactory;
import org.drools.guvnor.client.rpc.Asset;
import org.drools.guvnor.client.rpc.RuleFlowContentModel;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Frame;

/**
* The Business Process Editor, wrapping the Process Editor
*/
public class BusinessProcessEditor extends DirtyableComposite
    implements
    SaveEventListener,
    EditorWidget {

    private String    modelUUID;
    private Asset asset;
    private Frame     frame;

    public BusinessProcessEditor(Asset asset,
                                 RuleViewer viewer,
                                 ClientFactory clientFactory,
                                 EventBus eventBus) {
        this.asset = asset;
        modelUUID = asset.getUuid();
        initWidgets();
    }

    private void initWidgets() {
        String name = "/"+ApplicationPreferences.getDesignerContext()+"/editor/?uuid=" + modelUUID + "&profile="+ApplicationPreferences.getDesignerProfile();
        frame = new Frame( name );
        frame.getElement().setAttribute( "domain",
                                         Document.get().getDomain() );
        frame.setWidth( "100%" );
        frame.setHeight( "580px" );
        initWidget( frame );
        setWidth( "100%" );
        setHeight( "580px" );
    }

    private final native String callSave(Document frameDoc) /*-{
      return frameDoc.defaultView.ORYX.EDITOR.getSerializedJSON();
    }-*/;
   
    private final native String callPreprocessingData(Document frameDoc) /*-{
        return frameDoc.defaultView.ORYX.PREPROCESSING;
    }-*/;
   
    private final native String callCheckParsingErrors(Document frameDoc) /*-{
      return frameDoc.defaultView.ORYX.EDITOR.checkParsingErrors();
    }-*/;
   
    private final native void callShowParsingErrors(Document frameDoc) /*-{
      frameDoc.defaultView.ORYX.EDITOR.showParsingErrors();
    }-*/;
  
    public boolean hasErrors() {
      String errors = callCheckParsingErrors( ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement())).getContentDocument() );
      if(errors != null && errors.equals("false")) {
        return false;
      } else {
        callShowParsingErrors( ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement())).getContentDocument() );
        return true;
      }
    }

    public void onSave(SaveCommand saveCommand) {
        try {
          String s = callSave( ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement())).getContentDocument() );
          String p = callPreprocessingData( ((IFrameElement) ((com.google.gwt.dom.client.Element) frame.getElement())).getContentDocument() );
          if ( asset.getContent() == null ) {
            asset.setContent( new RuleFlowContentModel() );
          }
          ((RuleFlowContentModel) asset.getContent()).setXml( null );
          ((RuleFlowContentModel) asset.getContent()).setJson( s );
          ((RuleFlowContentModel) asset.getContent()).setPreprocessingdata(p);
        } catch ( Exception e ) {
            GWT.log( "JSNI method callSave() threw an exception:",
                     e );
            Window.alert( "JSNI method callSave() threw an exception: " + e );
        }

        saveCommand.save();
    }

    public void onAfterSave() {
    }
}
TOP

Related Classes of org.drools.guvnor.client.asseteditor.BusinessProcessEditor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.