我们现在针对RSSReader项目,使用Drag-Drop的Portal布局效果。下面就开始使用GXT内建好的DragSource和DropTarget。
首相,我们要做的是允许用户可以从NavPortlet中FeedList的里面拖拽一条feed,然后可以放置到FeedPortlet,接下来其feed的内容会自动的通过ItemGrid显示出来。
public static final String FEED_DD_GROUP = "feedDDGroup";
DragSource source = new DragSource(feedList) { @Override protected void onDragStart(DNDEvent event) { event.setData(feedList.getSelection()); } }; source.setGroup(RSSReaderConstants.FEED_DD_GROUP); add(feedList);//above
private void onFeedsDropped(DNDEvent event) { List<BeanModel> beanModels = event.getData(); for (BeanModel beanModel : beanModels) { Feed feed = beanModel.getBean(); final ItemGrid itemGrid = new ItemGrid(feed); TabItem tabItem = new TabItem(feed.getTitle()); tabItem.setId(feed.getUuid()); tabItem.setData("feed", feed); tabItem.add(itemGrid); tabItem.addListener(Events.Select, new Listener<TabPanelEvent>() { @Override public void handleEvent(TabPanelEvent be) { itemGrid.resetSelection(); } }); tabItem.setClosable(true); feedPanel.addTab(tabItem); } }
protected void onRender(Element parent, int index) { super.onRender(parent, index); DropTarget target = new DropTarget(this); }
protected void onRender(Element parent, int index) { super.onRender(parent, index); DropTarget target = new DropTarget(this) { @Override protected void onDragDrop(DNDEvent event) { super.onDragDrop(event); onFeedsDropped(event); } }; }
protected void onRender(Element parent, int index) { super.onRender(parent, index); DropTarget target = new DropTarget(this) { @Override protected void onDragDrop(DNDEvent event) { super.onDragDrop(event); onFeedsDropped(event); } }; target.setOperation(DND.Operation.COPY); target.setGroup(RSSReaderConstants.FEED_DD_GROUP); }