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();
}
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();
}
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;
}
}
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;
}
}
}
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;
}
Aggregations