Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz844820 - work in progress - using celltable for display
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Aug 23, 2012
1 parent 6bc2dba commit b2f4686
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 65 deletions.
@@ -0,0 +1,47 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY 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
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.editor;

import java.util.ArrayList;

import org.zanata.webtrans.client.presenter.TransUnitEditPresenter;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitProvidesKey;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.ListDataProvider;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Singleton
public class TransUnitsDataProvider extends ListDataProvider<TransUnit>
{

@Inject
public TransUnitsDataProvider()
{
super(TransUnitProvidesKey.KEY_PROVIDER);
}
}
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;

import org.zanata.webtrans.client.editor.HasPageNavigation;
import org.zanata.webtrans.client.editor.TransUnitsDataProvider;
import org.zanata.webtrans.client.rpc.AbstractAsyncCallback;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.TransUnitNavigationService;
Expand All @@ -33,6 +34,7 @@
import org.zanata.webtrans.shared.rpc.GetTransUnitsNavigation;
import org.zanata.webtrans.shared.rpc.GetTransUnitsNavigationResult;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.gwt.gen2.logging.shared.Log;
import com.google.inject.Inject;
import com.google.inject.Singleton;
Expand All @@ -46,17 +48,19 @@ public class PageNavigation implements HasPageNavigation
public static final int FIRST_PAGE = 0;
private final CachingDispatchAsync dispatcher;
private final TransUnitNavigationService navigationService;
private final TransUnitsDataProvider dataProvider;
//tracking variables
private int pageCount;
private int totalCount;
private GetTransUnitActionContext context;
private ArrayList<TransUnit> currentPageItems;
private ArrayList<TransUnit> currentPageItems = Lists.newArrayList();

@Inject
public PageNavigation(CachingDispatchAsync dispatcher, TransUnitNavigationService navigationService)
public PageNavigation(CachingDispatchAsync dispatcher, TransUnitNavigationService navigationService, TransUnitsDataProvider dataProvider)
{
this.dispatcher = dispatcher;
this.navigationService = navigationService;
this.dataProvider = dataProvider;
}

public void init(GetTransUnitActionContext context)
Expand Down Expand Up @@ -158,23 +162,26 @@ public void gotoPreviousPage()
}

@Override
public void gotoPage(int pageIndex, boolean forceReloadTable)
public void gotoPage(int pageIndex, boolean forceReload)
{
// TODO force reload
if (pageIndex > 0)
int page = normalizePageIndex(pageIndex);
if (page != navigationService.getCurrentPage() || forceReload)
{
int targetPage = Math.min(pageIndex, lastPage());
if (targetPage == navigationService.getCurrentPage())
{
return;
}
GetTransUnitActionContext newContext = context.setOffset(context.getCount() * targetPage).setTargetTransUnitId(null);
GetTransUnitActionContext newContext = context.setOffset(context.getCount() * page).setTargetTransUnitId(null);
Log.info(pageIndex + " page context: " + newContext);
requestTransUnitsAndUpdatePageIndex(newContext);
}
}

private int normalizePageIndex(int pageIndex)
{
if (pageIndex < 0)
{
return FIRST_PAGE;
}
else
{
gotoFirstPage();
return Math.min(lastPage(), pageIndex);
}
}

Expand All @@ -199,4 +206,9 @@ public String toString()
toString();
// @formatter:on
}

public int getTotalCount()
{
return totalCount;
}
}
@@ -0,0 +1,88 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY 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
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.presenter;

import org.zanata.webtrans.client.editor.TransUnitsDataProvider;
import org.zanata.webtrans.client.editor.table.GetTransUnitActionContext;
import org.zanata.webtrans.client.editor.table.PageNavigation;
import org.zanata.webtrans.client.events.DocumentSelectionEvent;
import org.zanata.webtrans.client.events.DocumentSelectionHandler;
import org.zanata.webtrans.client.view.TransUnitEditDisplay;
import org.zanata.webtrans.client.view.TransUnitListDisplay;
import org.zanata.webtrans.shared.model.TransUnit;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.inject.Inject;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class TransUnitEditPresenter extends WidgetPresenter<TransUnitEditDisplay> implements DocumentSelectionHandler
{

private final TransUnitEditDisplay display;
private final EventBus eventBus;
private final PageNavigation pageNavigation;
private final TransUnitListDisplay transUnitListDisplay;
private final AsyncDataProvider<TransUnit> dataProvider;

@Inject
public TransUnitEditPresenter(TransUnitEditDisplay display, EventBus eventBus, PageNavigation pageNavigation, TransUnitListDisplay transUnitListDisplay)
{
super(display, eventBus);
this.display = display;
this.eventBus = eventBus;
this.pageNavigation = pageNavigation;
this.transUnitListDisplay = transUnitListDisplay;
display.setDisplayTable(transUnitListDisplay);
dataProvider = new TransUnitsDataProvider();
dataProvider.addDataDisplay(transUnitListDisplay);
}

@Override
protected void onBind()
{

}

@Override
protected void onUnbind()
{
}

@Override
protected void onRevealDisplay()
{
}

@Override
public void onDocumentSelected(DocumentSelectionEvent event)
{
GetTransUnitActionContext context = GetTransUnitActionContext.of(event.getDocumentId()).setCount(10);
pageNavigation.init(context);

dataProvider.updateRowCount(pageNavigation.getTotalCount(), true);
}

}
Expand Up @@ -139,8 +139,7 @@ public Integer getRowIndex(TransUnit tu, boolean isFiltering, List<TransUnit> ro
{
if (transUnitId.equals(transUnit.getId()))
{
int row = n + (curPage * pageSize);
return row;
return n + (curPage * pageSize);
}
n++;
}
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.zanata.webtrans.client.presenter.PreviewState;
import org.zanata.webtrans.client.presenter.TransUnitReplaceInfo;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.shared.util.StringNotEmptyPredicate;

import com.google.common.base.Predicate;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -602,14 +603,7 @@ private static void appendContent(SafeHtmlBuilder sb, String content)

private static Collection<String> notEmptyContents(List<String> contents)
{
return Collections2.filter(contents, new Predicate<String>()
{
@Override
public boolean apply(String input)
{
return !Strings.isNullOrEmpty(input);
}
});
return Collections2.filter(contents, StringNotEmptyPredicate.INSTANCE);
}

public HasValue<Boolean> getCheckbox()
Expand Down
@@ -0,0 +1,30 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY 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
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.view;

import net.customware.gwt.presenter.client.widget.WidgetDisplay;

public interface TransUnitEditDisplay extends WidgetDisplay
{
void setDisplayTable(TransUnitListDisplay displayTable);

}
@@ -0,0 +1,60 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY 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
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class TransUnitEditView extends Composite implements TransUnitEditDisplay
{
interface TransUnitTableViewUiBinder extends UiBinder<VerticalPanel, TransUnitEditView>
{
}

private static TransUnitTableViewUiBinder uiBinder = GWT.create(TransUnitTableViewUiBinder.class);

private VerticalPanel rootPanel;

public TransUnitEditView()
{
rootPanel = uiBinder.createAndBindUi(this);
}

@Override
public void setDisplayTable(TransUnitListDisplay displayTable)
{
rootPanel.add(displayTable);
}

@Override
public Widget asWidget()
{
return rootPanel;
}
}
@@ -0,0 +1,6 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:VerticalPanel>

</g:VerticalPanel>
</ui:UiBinder>
@@ -0,0 +1,33 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY 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
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.view;

import org.zanata.webtrans.shared.model.TransUnit;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.view.client.HasData;
import com.google.inject.ImplementedBy;

@ImplementedBy(TransUnitListTable.class)
public interface TransUnitListDisplay extends HasData<TransUnit>, IsWidget
{
void setHighlightString(String highlightString);
}

0 comments on commit b2f4686

Please sign in to comment.