Skip to content

Instantly share code, notes, and snippets.

@jstefek
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save jstefek/10880034 to your computer and use it in GitHub Desktop.

Select an option

Save jstefek/10880034 to your computer and use it in GitHub Desktop.
package org.richfaces.fragment.dataTable;
import java.util.List;
import org.jboss.arquillian.graphene.Graphene;
import org.jboss.arquillian.graphene.fragment.Root;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.richfaces.fragment.common.picker.ChoicePicker;
public interface NewFragments {// KEEP FUNCTIONALITY AND 'BODY' SEPARATED
public interface FragmentBody {
WebElement getRootElement();
}
public interface FragmentFunctionality<B extends FragmentBody> {
public B elements();
}
public interface PageFragment<B extends FragmentBody, F extends FragmentFunctionality<B>> {
public F functions(); // or advanced
}
public interface VisibleFragmentFunctionality<T extends FragmentBody> {
boolean isVisible();
}
/////////////////////
// list
// base body for all lists
public interface ListBody extends FragmentBody {
public List<WebElement> getRows();
public WebElement getRow(ChoicePicker p);
}
// base functionality for all lists
public interface ListFunctionality<ROW, B extends ListBody> extends FragmentFunctionality<B> {
ROW getRow(int x); // create fragment from elements().getRow(x)
Class<ROW> getRowClass();
}
// base for all lists
public class AbstractRFList<ROW, B extends ListBody, F extends ListFunctionality<ROW, B>> implements PageFragment<B, F> {
@Override
public F functions() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
// CUSTOM functions = FACADE
public ROW getRow(int x) {
return functions().getRow(x);
}
}
public static class RFListBody implements ListBody {
@Root
private WebElement root;
@FindBy
private List<WebElement> rows;
@Override
public List<WebElement> getRows() {
return rows;
}
@Override
public WebElement getRow(ChoicePicker p) {
return p.pick(rows);
}
@Override
public WebElement getRootElement() {
return root;
}
}
public static class RFListFunctionality<ROW, B extends ListBody> implements ListFunctionality<ROW, B> {
@Override
public ROW getRow(int x) {
return Graphene.createPageFragment(getRowClass(), elements().getRows().get(x));
}
@Override
public Class<ROW> getRowClass() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public B elements() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
public static class SimpleListRow {
public WebElement getName() {
return null;
}
public WebElement getEmail() {
return null;
}
}
// EXTEND abstract class for your implementation
public class RFListImpl extends AbstractRFList<SimpleListRow, RFListBody, RFListFunctionality<SimpleListRow, RFListBody>> {
}
public static class RFListBodyWithDifferentSelectors extends RFListBody {
}
public class RFListWithDifferentSelectorsButSameFunctionality extends AbstractRFList<SimpleListRow, RFListBodyWithDifferentSelectors, RFListFunctionality<SimpleListRow, RFListBodyWithDifferentSelectors>> {
}
///////////////////////////////////
// Ordering List
public interface OLBody extends ListBody {
WebElement getUpButton();
}
public interface OLFunctionality<ROW, B extends OLBody> extends ListFunctionality<ROW, B> {
void moveThatBeforeThat();
// how will it behave when delaing with not primitive objects? should be fine
}
public class AbstractRFOrderingList<ROW, B extends OLBody, F extends OLFunctionality<ROW, B>> implements PageFragment<B, F> {
@Override
public F functions() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
// CUSTOM functions = FACADE
public <T extends AbstractRFOrderingList<ROW, B, F>> T moveThatBeforeThat(int x) {
functions().moveThatBeforeThat();
return (T) this; // Not sure how this will work
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment