Skip to content

Commit

Permalink
Fix and Genericize CSS extension web module
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarsballe committed Jan 18, 2016
1 parent 6f30d63 commit b32e32d
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 78 deletions.
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -10,7 +10,6 @@
import java.util.List;
import java.util.logging.Logger;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.ReuseIfModelsEqualStrategy;
import org.apache.wicket.model.IModel;
Expand All @@ -31,14 +30,14 @@ public class BandsPanel extends Panel {
private GeoServerTablePanel<CoverageDimensionInfo> bands;

public BandsPanel(String id, final CoverageInfo coverage) {
super(id, new Model(coverage));
super(id, new Model<CoverageInfo>(coverage));

// the parameters table
bands = new GeoServerTablePanel<CoverageDimensionInfo>("bands",
new CoverageDimensionsProvider(), true) {

@Override
protected Component getComponentForProperty(String id, IModel itemModel,
protected GeoServerTablePanel<CoverageDimensionInfo> getComponentForProperty(String id, IModel<CoverageDimensionInfo> itemModel,
Property<CoverageDimensionInfo> property) {
return null;
}
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -56,6 +56,8 @@

public class CssDemoPage extends GeoServerSecuredPage {

private static final long serialVersionUID = 356621271722561780L;

/**
* Eventually prefixes the
*
Expand All @@ -64,6 +66,7 @@ public class CssDemoPage extends GeoServerSecuredPage {
*/
public class StyleNameModel extends LoadableDetachableModel<String> {

private static final long serialVersionUID = 640854278050951419L;
private StyleInfo style;

public StyleNameModel(StyleInfo style) {
Expand Down Expand Up @@ -235,55 +238,65 @@ private void doMainLayout() {
final ModalWindow popup = new ModalWindow("popup");
mainContent.add(popup);
final StyleNameModel styleNameModel = new StyleNameModel(style);
final PropertyModel layerNameModel = new PropertyModel(layer, "prefixedName");
final PropertyModel<String> layerNameModel = new PropertyModel<String>(layer, "prefixedName");

mainContent.add(new AjaxLink("create.style", new ParamResourceModel(
mainContent.add(new AjaxLink<String>("create.style", new ParamResourceModel(
"CssDemoPage.createStyle", this)) {
private static final long serialVersionUID = 1276737009163734430L;

public void onClick(AjaxRequestTarget target) {
target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
popup.setInitialHeight(200);
popup.setInitialWidth(300);
popup.setTitle(new Model("Choose name for new style"));
popup.setTitle(new Model<String>("Choose name for new style"));
popup.setContent(new StyleNameInput(popup.getContentId(), CssDemoPage.this));
popup.show(target);
}
});

mainContent.add(new SimpleAjaxLink("change.style", styleNameModel) {
mainContent.add(new SimpleAjaxLink<String>("change.style", styleNameModel) {
private static final long serialVersionUID = -3767935899990478209L;

public void onClick(AjaxRequestTarget target) {
target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
popup.setInitialHeight(400);
popup.setInitialWidth(600);
popup.setTitle(new Model("Choose style to edit"));
popup.setTitle(new Model<String>("Choose style to edit"));
popup.setContent(new StyleChooser(popup.getContentId(), CssDemoPage.this));
popup.show(target);
}
});
mainContent.add(new SimpleAjaxLink("change.layer", layerNameModel) {
mainContent.add(new SimpleAjaxLink<String>("change.layer", layerNameModel) {
private static final long serialVersionUID = 7341058018479354596L;

public void onClick(AjaxRequestTarget target) {
target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
popup.setInitialHeight(400);
popup.setInitialWidth(600);
popup.setTitle(new Model("Choose layer to edit"));
popup.setTitle(new Model<String>("Choose layer to edit"));
popup.setContent(new LayerChooser(popup.getContentId(), CssDemoPage.this));
popup.show(target);
}
});
mainContent.add(new AjaxLink("associate.styles", new ParamResourceModel(
mainContent.add(new AjaxLink<String>("associate.styles", new ParamResourceModel(
"CssDemoPage.associateStyles", this)) {
private static final long serialVersionUID = -5694226354260865370L;

public void onClick(AjaxRequestTarget target) {
target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
popup.setInitialHeight(400);
popup.setInitialWidth(600);
popup.setTitle(new Model("Choose layers to associate"));
popup.setTitle(new Model<String>("Choose layers to associate"));
popup.setContent(new MultipleLayerChooser(popup.getContentId(), CssDemoPage.this));
popup.show(target);
}
});
ParamResourceModel associateToLayer = new ParamResourceModel(
"CssDemoPage.associateDefaultStyle", this, styleNameModel, layerNameModel);
final SimpleAjaxLink associateDefaultStyle = new SimpleAjaxLink("associate.default.style",
new Model(), associateToLayer) {
final SimpleAjaxLink<String> associateDefaultStyle = new SimpleAjaxLink<String>("associate.default.style",
new Model<String>(), associateToLayer) {
private static final long serialVersionUID = -1861639192229523093L;

public void onClick(final AjaxRequestTarget linkTarget) {
final Component theComponent = this;
dialog.setResizable(false);
Expand All @@ -292,6 +305,8 @@ public void onClick(final AjaxRequestTarget linkTarget) {
dialog.setInitialHeight(7);
dialog.setInitialWidth(50);
dialog.showOkCancel(linkTarget, new DialogDelegate() {
/** serialVersionUID */
private static final long serialVersionUID = -406178892098125499L;
boolean success = false;

@Override
Expand Down Expand Up @@ -334,6 +349,8 @@ protected Component getContents(String id) {
mainContent.add(associateDefaultStyle);

final IModel<String> sldModel = new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 879601998074117903L;

public String getObject() {
try {
// if file already in css format transform to sld, otherwise load the SLD file
Expand Down Expand Up @@ -366,22 +383,28 @@ public String getObject() {
}
};

final CompoundPropertyModel model = new CompoundPropertyModel<CssDemoPage>(CssDemoPage.this);
final CompoundPropertyModel<CssDemoPage> model = new CompoundPropertyModel<CssDemoPage>(CssDemoPage.this);
List<ITab> tabs = new ArrayList<ITab>();
tabs.add(new PanelCachingTab(new AbstractTab(new Model("Generated SLD")) {
tabs.add(new PanelCachingTab(new AbstractTab(new Model<String>("Generated SLD")) {
private static final long serialVersionUID = 8555701231692660833L;

public Panel getPanel(String id) {
SLDPreviewPanel panel = new SLDPreviewPanel(id, sldModel);
sldPreview = panel.getLabel();
return panel;
}
}));
tabs.add(new PanelCachingTab(new AbstractTab(new Model("Map")) {
tabs.add(new PanelCachingTab(new AbstractTab(new Model<String>("Map")) {
private static final long serialVersionUID = -6162351963705823223L;

public Panel getPanel(String id) {
return map = new OpenLayersMapPanel(id, layer, style);
}
}));
if (layer.getResource() instanceof FeatureTypeInfo) {
tabs.add(new PanelCachingTab(new AbstractTab(new Model("Data")) {
tabs.add(new PanelCachingTab(new AbstractTab(new Model<String>("Data")) {
private static final long serialVersionUID = 4184410057835108176L;

public Panel getPanel(String id) {
try {
return new DataPanel(id, model, (FeatureTypeInfo) layer.getResource());
Expand All @@ -391,13 +414,17 @@ public Panel getPanel(String id) {
};
}));
} else if (layer.getResource() instanceof CoverageInfo) {
tabs.add(new PanelCachingTab(new AbstractTab(new Model("Data")) {
tabs.add(new PanelCachingTab(new AbstractTab(new Model<String>("Data")) {
private static final long serialVersionUID = 646758948234232061L;

public Panel getPanel(String id) {
return new BandsPanel(id, (CoverageInfo) layer.getResource());
};
}));
}
tabs.add(new AbstractTab(new Model("CSS Reference")) {
tabs.add(new AbstractTab(new Model<String>("CSS Reference")) {
private static final long serialVersionUID = 2107911061109604980L;

public Panel getPanel(String id) {
return new DocsPanel(id);
}
Expand All @@ -408,7 +435,7 @@ public Panel getPanel(String id) {

mainContent.add(new StylePanel("style.editing", model, CssDemoPage.this, cssFile));

mainContent.add(new AjaxTabbedPanel("context", tabs));
mainContent.add(new AjaxTabbedPanel<ITab>("context", tabs));

add(mainContent);
add(dialog = new GeoServerDialog("dialog"));
Expand Down
Expand Up @@ -13,6 +13,7 @@

public class CssValidator implements IValidator<String> {

private static final long serialVersionUID = 2801344384920672147L;
static final Logger LOGGER = Logging.getLogger(CssValidator.class);

@Override
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -34,6 +34,8 @@
import com.vividsolutions.jts.geom.Geometry;

public class DataPanel extends Panel {
private static final long serialVersionUID = -2635691554700860434L;

static final Logger LOGGER = Logging.getLogger(DataPanel.class);

String featureTypeId;
Expand All @@ -55,13 +57,17 @@ public DataPanel(String id, IModel<CssDemoPage> model, final FeatureTypeInfo lay
add(attsContainer);
final GeoServerTablePanel<DataAttribute> attributes = new GeoServerTablePanel<DataAttribute>("attributes", summaries) {

private static final long serialVersionUID = 7753093373969576568L;

@Override
protected Component getComponentForProperty(String id, final IModel itemModel,
protected Component getComponentForProperty(String id, final IModel<DataAttribute> itemModel,
Property<DataAttribute> property) {
if(DataAttributesProvider.COMPUTE_STATS.equals(property.getName())) {
Fragment f = new Fragment(id, "computeStatsFragment", DataPanel.this);
f.add(new AjaxLink<Void>("computeStats") {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
DataAttribute attribute = (DataAttribute) itemModel.getObject();
Expand Down Expand Up @@ -89,7 +95,7 @@ public void onClick(AjaxRequestTarget target) {

protected void updateAttributeStats(DataAttribute attribute) throws IOException {
FeatureTypeInfo featureType = GeoServerApplication.get().getCatalog().getFeatureType(featureTypeId);
FeatureSource fs = featureType.getFeatureSource(null, null);
FeatureSource<?, ?> fs = featureType.getFeatureSource(null, null);

// check we can compute min and max
PropertyDescriptor pd = fs.getSchema().getDescriptor(attribute.getName());
Expand All @@ -102,7 +108,7 @@ protected void updateAttributeStats(DataAttribute attribute) throws IOException
// query to the dbms in case of such data source)
Query q = new Query();
q.setPropertyNames(new String[] {attribute.getName()});
FeatureCollection fc = fs.getFeatures(q);
FeatureCollection<?, ?> fc = fs.getFeatures(q);
MinVisitor minVisitor = new MinVisitor(attribute.getName());
MaxVisitor maxVisitor = new MaxVisitor(attribute.getName());
fc.accepts(minVisitor, null);
Expand All @@ -114,11 +120,11 @@ protected void updateAttributeStats(DataAttribute attribute) throws IOException
}

private Feature getSampleFeature(FeatureTypeInfo layerInfo) throws IOException {
FeatureSource fs = layerInfo.getFeatureSource(null, null);
FeatureSource<?, ?> fs = layerInfo.getFeatureSource(null, null);
Query q = new Query();
q.setMaxFeatures(1);
FeatureCollection features = fs.getFeatures(q);
FeatureIterator fi = null;
FeatureCollection<?, ?> features = fs.getFeatures(q);
FeatureIterator<?> fi = null;
Feature sample = null;
try {
fi = features.features();
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -8,6 +8,8 @@
import org.apache.wicket.markup.html.panel.Panel;

public class DocsPanel extends Panel {
private static final long serialVersionUID = -2922846008087612497L;

public DocsPanel(String id) {
super(id);
}
Expand Down
@@ -1,4 +1,4 @@
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -25,7 +25,11 @@

public class LayerChooser extends Panel {

private static final long serialVersionUID = -127345071729297975L;

private static class LayerProvider extends GeoServerDataProvider<LayerInfo> {
private static final long serialVersionUID = -2117784735301652240L;

private CssDemoPage demo;

public LayerProvider(CssDemoPage demo) {
Expand All @@ -34,20 +38,26 @@ public LayerProvider(CssDemoPage demo) {

public static Property<LayerInfo> workspace =
new AbstractProperty<LayerInfo>("Workspace") {
private static final long serialVersionUID = -7055816211775541759L;

public Object getPropertyValue(LayerInfo x) {
return x.getResource().getStore().getWorkspace().getName();
}
};

public static Property<LayerInfo> store =
new AbstractProperty<LayerInfo>("Store") {
private static final long serialVersionUID = -4021230907568644439L;

public Object getPropertyValue(LayerInfo x) {
return x.getResource().getStore().getName();
}
};

public static Property<LayerInfo> name =
new AbstractProperty<LayerInfo>("Layer") {
private static final long serialVersionUID = 8913729089849537790L;

public Object getPropertyValue(LayerInfo x) {
return x.getName();
}
Expand All @@ -69,19 +79,24 @@ public LayerChooser(final String id, final CssDemoPage demo) {
LayerProvider provider = new LayerProvider(demo);
GeoServerTablePanel<LayerInfo> table =
new GeoServerTablePanel<LayerInfo>("layer.table", provider) {
private static final long serialVersionUID = 1196129584558094662L;

@Override
public Component getComponentForProperty(
String id, IModel value, Property<LayerInfo> property
String id, IModel<LayerInfo> value, Property<LayerInfo> property
) {
final LayerInfo layer = (LayerInfo) value.getObject();
final String text = property.getPropertyValue(layer).toString();

if (property == LayerProvider.name) {
return new Fragment(id, "layer.link", LayerChooser.this) {
private static final long serialVersionUID = -7619814477490657757L;

{
add(new AjaxLink("link") {
add(new AjaxLink<Object>("link") {
private static final long serialVersionUID = -986789496671734252L;
{
add(new Label("layer.name", new Model(text)));
add(new Label("layer.name", new Model<String>(text)));
}
@Override
public void onClick(AjaxRequestTarget target) {
Expand Down

0 comments on commit b32e32d

Please sign in to comment.