Created
December 17, 2014 13:43
-
-
Save ederign/a57c86715330899ab66b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.uberfire.ext.perspective.editor.client.main; | |
import javax.annotation.PostConstruct; | |
import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
import com.github.gwtbootstrap.client.ui.Button; | |
import com.github.gwtbootstrap.client.ui.constants.IconType; | |
import com.github.gwtbootstrap.client.ui.resources.ButtonSize; | |
import com.google.gwt.event.dom.client.ClickEvent; | |
import com.google.gwt.event.dom.client.ClickHandler; | |
import com.google.gwt.user.client.Window; | |
import org.jboss.errai.ioc.client.api.AfterInitialization; | |
import org.uberfire.client.annotations.WorkbenchMenu; | |
import org.uberfire.client.annotations.WorkbenchPartTitle; | |
import org.uberfire.client.annotations.WorkbenchPartView; | |
import org.uberfire.client.annotations.WorkbenchScreen; | |
import org.uberfire.client.mvp.PlaceManager; | |
import org.uberfire.client.mvp.UberView; | |
import org.uberfire.ext.perspective.editor.client.panels.perspective.PerspectivePresenter; | |
import org.uberfire.ext.perspective.editor.client.panels.perspective.PerspectiveView; | |
import org.uberfire.lifecycle.OnOpen; | |
import org.uberfire.workbench.model.menu.MenuFactory; | |
import org.uberfire.workbench.model.menu.MenuItem; | |
import org.uberfire.workbench.model.menu.Menus; | |
import org.uberfire.workbench.model.menu.impl.BaseMenuCustom; | |
@ApplicationScoped | |
@WorkbenchScreen(identifier = "PerspectiveEditorMainPresenter") | |
public class PerspectiveEditorMainPresenter { | |
public interface View extends UberView<PerspectiveEditorMainPresenter> { | |
void setup( PerspectiveView containerView ); | |
} | |
@Inject | |
private View view; | |
@Inject | |
private PlaceManager placeManager; | |
@Inject | |
private PerspectivePresenter perspectivePresenter; | |
@PostConstruct | |
public void init() { | |
} | |
@AfterInitialization | |
public void loadContent() { | |
} | |
@OnOpen | |
public void onOpen() { | |
perspectivePresenter.init(); | |
view.setup( perspectivePresenter.getView() ); | |
prepareDnd(this); | |
} | |
private native void prepareDnd(PerspectiveEditorMainPresenter js)/*-{ | |
(function( $ ) { | |
$.fn.simulateDragDrop = function(options) { | |
return this.each(function() { | |
new $.simulateDragDrop(this, options); | |
}); | |
}; | |
$.simulateDragDrop = function(elem, options) { | |
this.options = options; | |
this.simulateEvent(elem, options); | |
}; | |
$.extend($.simulateDragDrop.prototype, { | |
simulateEvent: function(elem, options) { | |
var type = 'dragstart'; | |
var event = this.createEvent(type); | |
this.dispatchEvent(elem, type, event); | |
type = 'drop'; | |
var dropEvent = this.createEvent(type, {}); | |
dropEvent.dataTransfer = event.dataTransfer; | |
this.dispatchEvent($(options.dropTarget)[0], type, dropEvent); | |
type = 'dragend'; | |
var dragEndEvent = this.createEvent(type, {}); | |
dragEndEvent.dataTransfer = event.dataTransfer; | |
this.dispatchEvent(elem, type, dragEndEvent); | |
}, | |
createEvent: function(type) { | |
var event = document.createEvent("CustomEvent"); | |
event.initCustomEvent(type, true, true, null); | |
event.dataTransfer = { | |
data: { | |
}, | |
setData: function(type, val){ | |
this.data[type] = val; | |
}, | |
getData: function(type){ | |
return this.data[type]; | |
} | |
}; | |
return event; | |
}, | |
dispatchEvent: function(elem, type, event) { | |
if(elem.dispatchEvent) { | |
elem.dispatchEvent(event); | |
}else if( elem.fireEvent ) { | |
elem.fireEvent("on"+type, event); | |
} | |
} | |
}); | |
})($wnd.jQuery); | |
}-*/; | |
@WorkbenchPartTitle | |
public String getTitle() { | |
return "Perspective Layout"; | |
} | |
@WorkbenchPartView | |
public UberView<PerspectiveEditorMainPresenter> getView() { | |
return view; | |
} | |
@WorkbenchMenu | |
public Menus buildMenu() { | |
return MenuFactory | |
.newTopLevelCustomMenu( buildReloadMenu() ).endMenu().newTopLevelCustomMenu( buildLoadMenu() ).endMenu().newTopLevelCustomMenu( buildSaveMenu() ).endMenu().build(); | |
} | |
private MenuFactory.CustomMenuBuilder buildReloadMenu() { | |
return new MenuFactory.CustomMenuBuilder() { | |
@Override | |
public void push( MenuFactory.CustomMenuBuilder element ) { | |
} | |
@Override | |
public MenuItem build() { | |
return new BaseMenuCustom<Button>() { | |
@Override | |
public Button build() { | |
return new Button() { | |
{ | |
setIcon( IconType.REFRESH ); | |
setSize( ButtonSize.MINI ); | |
addClickHandler( new ClickHandler() { | |
@Override | |
public void onClick( ClickEvent event ) { | |
perspectivePresenter.init(); | |
} | |
} ); | |
} | |
}; | |
} | |
}; | |
} | |
}; | |
} | |
private MenuFactory.CustomMenuBuilder buildSaveMenu() { | |
return new MenuFactory.CustomMenuBuilder() { | |
@Override | |
public void push( MenuFactory.CustomMenuBuilder element ) { | |
} | |
@Override | |
public MenuItem build() { | |
return new BaseMenuCustom<Button>() { | |
@Override | |
public Button build() { | |
return new Button() { | |
{ | |
setIcon( IconType.SAVE ); | |
setSize( ButtonSize.MINI ); | |
addClickHandler( new ClickHandler() { | |
@Override | |
public void onClick( ClickEvent event ) { | |
perspectivePresenter.savePopup(); | |
} | |
} ); | |
} | |
}; | |
} | |
}; | |
} | |
}; | |
} | |
private MenuFactory.CustomMenuBuilder buildLoadMenu() { | |
return new MenuFactory.CustomMenuBuilder() { | |
@Override | |
public void push( MenuFactory.CustomMenuBuilder element ) { | |
} | |
@Override | |
public MenuItem build() { | |
return new BaseMenuCustom<Button>() { | |
@Override | |
public Button build() { | |
return new Button() { | |
{ | |
setIcon( IconType.FOLDER_OPEN ); | |
setSize( ButtonSize.MINI ); | |
addClickHandler( new ClickHandler() { | |
@Override | |
public void onClick( ClickEvent event ) { | |
perspectivePresenter.loadPopup(); | |
} | |
} ); | |
} | |
}; | |
} | |
}; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment