Skip to content
Snippets Groups Projects
Commit eb0928fa authored by Kisslinger's avatar Kisslinger
Browse files

Extended use-cases with inputs and outputs

refs 791
parent c8ab9803
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.dialog;
import static org.eclipse.jface.dialogs.IDialogConstants.CANCEL_ID;
import static org.eclipse.jface.dialogs.IDialogConstants.CANCEL_LABEL;
import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID;
import static org.eclipse.jface.dialogs.IDialogConstants.OK_LABEL;
import static org.eclipse.wb.swt.ResourceManager.decorateImage;
import static org.eclipse.wb.swt.ResourceManager.getPluginImage;
import static org.eclipse.wb.swt.SWTResourceManager.BOTTOM_RIGHT;
import java.util.ArrayList;
import java.util.List;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* This dialog offers a common dialog to show multi-root tree structures and
* allows user to select multiple items in the tree. It also offers an interface
* to edit the tree on the fly.
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: EA7353C37324917BDACDE1094C9351FB
*/
public class ElementTreeMultiSelectDialog extends TitleAreaDialog {
/** Default content provider */
private static class EmptyTreeContentProvider extends TreeContentProviderBase {
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
}
/** Label provider which adds selected icon on the original icon */
private class DecorateLabelProvider extends LabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
return labelSupport.getText(element);
}
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
Image image = labelSupport.getImage(element);
if(!selectedElements.contains(element))
return image;
Image icon = getPluginImage("org.eclipse.ui", "/icons/full/ovr16/pinned_ovr.gif");
if(icon == null)
return image;
return decorateImage(image, icon, BOTTOM_RIGHT);
}
}
/** roots of the tree */
private ArrayList<Object> rootElements;
/** selected element */
private ArrayList<Object> selectedElements;
/** content provider for the roots */
private ITreeContentProvider contentSupport;
/** label provider for the elements */
private ILabelProvider labelSupport;
/** The gui composite */
private ElementTreeMultiSelectDialogGUI gui;
/** Constructor */
public ElementTreeMultiSelectDialog(Shell parentShell, List<?> roots, List<?> selected,
ITreeContentProvider contentProvider, ILabelProvider labelProvider) {
super(parentShell);
if(roots == null)
rootElements = new ArrayList<Object>();
else
rootElements = new ArrayList<Object>(roots);
if(selected == null)
selectedElements = new ArrayList<Object>();
else
selectedElements = new ArrayList<Object>(selected);
contentSupport = contentProvider;
labelSupport = labelProvider;
}
/** {@inheritDoc} */
@Override
protected Control createDialogArea(Composite parent) {
setHelpAvailable(false);
setTitle("Select");
setMessage("Select one or more elements");
// create controls
Composite area = (Composite)super.createDialogArea(parent);
gui = new ElementTreeMultiSelectDialogGUI(area, SWT.NONE);
gui.getSelectButton().addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
selectElement();
}
});
gui.getDeselectButton().addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
deselectElement();
}
});
gui.getElementTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
selectElement();
}
});
gui.getSelectTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
deselectElement();
}
});
// label, content and input
gui.getElementTreeViewer().setLabelProvider(new DecorateLabelProvider());
gui.getSelectTreeViewer().setLabelProvider(new DecorateLabelProvider());
gui.getElementTreeViewer().setContentProvider(
new MultiRootTreeContentProvider(rootElements, contentSupport));
gui.getSelectTreeViewer().setContentProvider(
new MultiRootTreeContentProvider(selectedElements, new EmptyTreeContentProvider()));
gui.getElementTreeViewer().setInput(rootElements);
gui.getSelectTreeViewer().setInput(selectedElements);
return area;
}
/** {@inheritDoc} */
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, OK_ID, OK_LABEL, false);
createButton(parent, CANCEL_ID, CANCEL_LABEL, true);
}
/** {@inheritDoc} */
@Override
protected Point getInitialSize() {
return new Point(640, 480);
}
/** Returns rootElements. */
public List<Object> getRootElements() {
return rootElements;
}
/** Returns selectedElements. */
public List<Object> getSelectedElements() {
return selectedElements;
}
/** Returns contentSupport. */
public IStructuredContentProvider getContentProvider() {
return contentSupport;
}
/** Returns labelSupport. */
public ILabelProvider getLabelProvider() {
return labelSupport;
}
/** Add selected elements to the select list. */
private void selectElement() {
try {
// find the path to the element
ITreeSelection selection = (ITreeSelection)gui.getElementTreeViewer().getSelection();
if(selection.getPaths() == null)
return;
for(TreePath path : selection.getPaths()) {
if(selectedElements.contains(path.getLastSegment()))
continue;
selectedElements.add(path.getLastSegment());
gui.getSelectTreeViewer().add(selectedElements, path.getLastSegment());
gui.getElementTreeViewer().update(path.getLastSegment(), null);
}
} catch(Exception e2) {
e2.printStackTrace();
}
}
/** Remove selected elements from the select list */
private void deselectElement() {
try {
// find the path to the element
ITreeSelection selection = (ITreeSelection)gui.getSelectTreeViewer().getSelection();
if(selection.getPaths() == null)
return;
for(TreePath path : selection.getPaths()) {
if(selectedElements.remove(path.getLastSegment())) {
gui.getSelectTreeViewer().remove(path.getLastSegment());
gui.getElementTreeViewer().update(path.getLastSegment(), null);
}
}
} catch(Exception e2) {
e2.printStackTrace();
}
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.dialog;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
/**
* GUI for {@link ElementTreeMultiSelectDialog}
*
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 05250999EEE7D41BBC53649DB1E4B800
*/
public class ElementTreeMultiSelectDialogGUI extends Composite {
/** the left tree viewer */
private TreeViewer elementTreeViewer;
/** the right tree viewer */
private TreeViewer selectTreeViewer;
/** the select button */
private Button selectButton;
/** the deselect button */
private Button deselectButton;
/**
* Default Constructor for GUI builder.
*/
public ElementTreeMultiSelectDialogGUI(Composite parent, int style) {
super(parent, style);
GridLayout gl_container = new GridLayout(4, false);
gl_container.verticalSpacing = 2;
gl_container.marginRight = 5;
gl_container.marginLeft = 5;
gl_container.marginBottom = 5;
gl_container.marginTop = 5;
gl_container.marginWidth = 0;
gl_container.marginHeight = 0;
setLayout(gl_container);
setLayoutData(new GridData(GridData.FILL_BOTH));
elementTreeViewer = new TreeViewer(this, SWT.BORDER);
Tree elementTree = elementTreeViewer.getTree();
elementTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Composite toolbarbox = new Composite(this, SWT.NONE);
GridLayout gl_toolbarbox = new GridLayout(1, false);
gl_toolbarbox.verticalSpacing = 2;
gl_toolbarbox.horizontalSpacing = 2;
gl_toolbarbox.marginHeight = 0;
gl_toolbarbox.marginWidth = 0;
toolbarbox.setLayout(gl_toolbarbox);
toolbarbox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 1));
selectButton = new Button(toolbarbox, SWT.NONE);
selectButton.setText(">>");
deselectButton = new Button(toolbarbox, SWT.NONE);
deselectButton.setText("<<");
selectTreeViewer = new TreeViewer(this, SWT.BORDER);
Tree selectTree = selectTreeViewer.getTree();
selectTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
}
/** Returns elementTreeViewer. */
public TreeViewer getElementTreeViewer() {
return elementTreeViewer;
}
/** Returns selectTreeViewer. */
public TreeViewer getSelectTreeViewer() {
return selectTreeViewer;
}
/** Returns selectButton. */
public Button getSelectButton() {
return selectButton;
}
/** Returns deselectButton. */
public Button getDeselectButton() {
return deselectButton;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment