Search in sources :

Example 6 with Rule

use of org.geotools.styling.Rule in project hale by halestudio.

the class RuleStylePage method updateEditor.

/**
 * Display the editor for the current rule in the editor area
 */
private void updateEditor() {
    if (currentEditor != null) {
        currentEditor.getControl().dispose();
    }
    if (currentIndex >= 0 && currentIndex < rules.size()) {
        Rule rule = rules.get(currentIndex).getRule();
        currentEditor = createEditor(rule, editorArea);
        editorArea.layout(true);
    }
    updateButtonState();
}
Also used : Rule(org.geotools.styling.Rule)

Example 7 with Rule

use of org.geotools.styling.Rule in project hale by halestudio.

the class RuleStylePage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    changed = false;
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));
    // DISABLED - this method seems to change the rule order - Rule[]
    // ruleArray = SLD.rules(getParent().getStyle());
    // use list instead:
    List<Rule> ruleList;
    try {
        ruleList = getParent().getStyle().featureTypeStyles().get(0).rules();
    } catch (Exception e) {
        ruleList = new ArrayList<Rule>();
    }
    // init index
    if (ruleList.size() > 0) {
        currentIndex = 0;
    } else {
        currentIndex = -1;
    }
    currentEditor = null;
    // populate rule map
    rules = new ArrayList<RuleItem>(ruleList.size() + 5);
    for (int i = 0; i < ruleList.size(); i++) {
        Rule rule = ruleList.get(i);
        if (rule != null) {
            rules.add(new RuleItem(rule));
        }
    }
    // rule list
    Composite ruleArea = new Composite(page, SWT.NONE);
    ruleArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    GridLayout leftLayout = new GridLayout(5, true);
    leftLayout.horizontalSpacing = 1;
    leftLayout.verticalSpacing = 1;
    ruleArea.setLayout(leftLayout);
    // label
    Label rulesLabel = new Label(ruleArea, SWT.NONE);
    rulesLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 5, 1));
    rulesLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    rulesLabel.setText(Messages.RuleStylePage_RuleLabelText);
    // viewer
    listViewer = new ListViewer(ruleArea);
    listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 5, 1));
    listViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // ignore
        }

        @Override
        public void dispose() {
        // ignore
        }

        @SuppressWarnings("unchecked")
        @Override
        public Object[] getElements(Object inputElement) {
            try {
                List<RuleItem> rules = (List<RuleItem>) inputElement;
                return rules.toArray();
            } catch (Exception e) {
                return null;
            }
        }
    });
    listViewer.setInput(rules);
    if (currentIndex >= 0 && currentIndex < rules.size()) {
        listViewer.setSelection(new StructuredSelection(rules.get(currentIndex)));
    }
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            RuleItem item = (RuleItem) ((IStructuredSelection) event.getSelection()).getFirstElement();
            int newIndex = rules.indexOf(item);
            if (currentIndex != newIndex) {
                try {
                    updateCurrentRule();
                } catch (Exception e) {
                    log.userError("Invalid editor state, could not update rule.", e);
                    return;
                }
                currentIndex = newIndex;
                updateEditor();
            }
        }
    });
    // buttons
    addButton = new Button(ruleArea, SWT.PUSH);
    addButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    addButton.setImage(addImage);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    addButton.setToolTipText(Messages.RuleStylePage_AddRuleButtonToolTippText);
    removeButton = new Button(ruleArea, SWT.PUSH);
    removeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    removeButton.setImage(removeImage);
    removeButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeCurrentRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    removeButton.setToolTipText(Messages.RuleStylePage_RemoveRuleButtonToolTippText);
    upButton = new Button(ruleArea, SWT.PUSH);
    upButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    upButton.setImage(upImage);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveCurrentRuleUp();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    upButton.setToolTipText(Messages.RuleStylePage_UpRuleButtonToolTippText);
    downButton = new Button(ruleArea, SWT.PUSH);
    downButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    downButton.setImage(downImage);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveCurrentRuleDown();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    downButton.setToolTipText(Messages.RuleStylePage_DownRuleButtonToolTippText);
    renameButton = new Button(ruleArea, SWT.PUSH);
    renameButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    renameButton.setImage(renameImage);
    renameButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            renameCurrentRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    renameButton.setToolTipText(Messages.RuleStylePage_RenameRuleButtonToolTippText);
    // editor area
    editorArea = new Composite(page, SWT.NONE);
    editorArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    editorArea.setLayout(new FillLayout());
    setControl(page);
    updateEditor();
}
Also used : ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ListViewer(org.eclipse.jface.viewers.ListViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Rule(org.geotools.styling.Rule) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 8 with Rule

use of org.geotools.styling.Rule in project hale by halestudio.

the class RuleStylePage method moveCurrentRuleDown.

/**
 * Move the current rule down
 */
protected void moveCurrentRuleDown() {
    if (currentIndex >= 0 && currentIndex < rules.size() - 1) {
        try {
            updateCurrentRule();
        } catch (Exception e) {
            log.userError("Invalid editor state, could not update rule.", e);
            return;
        }
        RuleItem item1 = rules.get(currentIndex);
        Rule temp = item1.getRule();
        RuleItem item2 = rules.get(++currentIndex);
        item1.setRule(item2.getRule());
        item2.setRule(temp);
        listViewer.refresh(true);
        listViewer.setSelection(new StructuredSelection(item2));
        updateEditor();
        changed = true;
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Rule(org.geotools.styling.Rule)

Example 9 with Rule

use of org.geotools.styling.Rule in project hale by halestudio.

the class RuleStylePage method updateCurrentRule.

/**
 * Update the {@link Rule} whose editor is currently open
 *
 * @throws Exception if an error occurs during the update
 */
private void updateCurrentRule() throws Exception {
    if (currentEditor != null && currentEditor.isChanged()) {
        Rule rule = currentEditor.getValue();
        if (rule != null) {
            rules.get(currentIndex).setRule(rule);
            changed = true;
        }
    }
}
Also used : Rule(org.geotools.styling.Rule)

Example 10 with Rule

use of org.geotools.styling.Rule in project hale by halestudio.

the class RuleEditor method getValue.

/**
 * @see Editor#getValue()
 */
@Override
public Rule getValue() throws Exception {
    Rule rule = styleBuilder.createRule(symbolizerEditor.getValue());
    rule.setFilter(filterEditor.getValue());
    return rule;
}
Also used : Rule(org.geotools.styling.Rule)

Aggregations

Rule (org.geotools.styling.Rule)110 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)65 Style (org.geotools.styling.Style)60 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)51 Test (org.junit.Test)48 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)26 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 Symbolizer (org.geotools.styling.Symbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)19 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)16 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)16 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)13 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)11 ArrayList (java.util.ArrayList)11 Filter (org.opengis.filter.Filter)11 UserLayerImpl (org.geotools.styling.UserLayerImpl)10 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)8