Skip to content
Snippets Groups Projects
Commit 69f5ba96 authored by Dongyue Mou's avatar Dongyue Mou
Browse files

set mira back to yellow.

moved dialog package to base.
removed type constraint in EcoreUtils#pickInstanceOf

refs 301
parent 9039feb3
No related branches found
No related tags found
No related merge requests found
Showing
with 1178 additions and 7 deletions
......@@ -14,6 +14,7 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.compose,
org.fortiss.tooling.base.ui.contentprovider,
org.fortiss.tooling.base.ui.databinding,
org.fortiss.tooling.base.ui.dialog,
org.fortiss.tooling.base.ui.dnd.gef,
org.fortiss.tooling.base.ui.dnd.jface,
org.fortiss.tooling.base.ui.editor,
......
/*--------------------------------------------------------------------------+
$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.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.eclipse.jface.dialogs.IDialogConstants;
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.jface.viewers.TreeViewer;
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.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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.fortiss.tooling.base.ui.contentprovider.TreeContentProviderBase;
/**
* 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: D341EE32101C47A679073DA4BA1586F7
*/
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);
}
}
/** GUI Factory */
private final FormToolkit formToolkit = new FormToolkit(
Display.getDefault());
/** editing module */
private IDialogEditSupport dialogEditSupport;
/** 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;
/** left tree viewer */
private TreeViewer elementTreeViewer;
/** right tree viewer */
private TreeViewer selectTreeViewer;
/** Constructor */
public ElementTreeMultiSelectDialog(Shell parentShell, List<?> roots,
List<?> selected, ITreeContentProvider contentProvider,
ILabelProvider labelProvider, IDialogEditSupport edit) {
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);
dialogEditSupport = edit;
contentSupport = contentProvider;
labelSupport = labelProvider;
}
/** {@inheritDoc} */
@Override
protected Control createDialogArea(Composite parent) {
// CAUTION: The code below is automatically generated, do not edit
// manually!
setHelpAvailable(false);
setTitle("Select");
setMessage("Select one or more elements");
// create controls
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
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;
container.setLayout(gl_container);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite lefttoolbar = new Composite(container, SWT.NONE);
lefttoolbar.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false,
true, 1, 1));
GridLayout gl_lefttoolbar = new GridLayout(1, false);
gl_lefttoolbar.verticalSpacing = 2;
gl_lefttoolbar.horizontalSpacing = 2;
gl_lefttoolbar.marginHeight = 0;
gl_lefttoolbar.marginWidth = 0;
lefttoolbar.setLayout(gl_lefttoolbar);
Button createButton = new Button(lefttoolbar, SWT.NONE);
createButton.setImage(getPluginImage("org.eclipse.ui",
"/icons/full/obj16/add_obj.gif"));
formToolkit.adapt(createButton, true, true);
Button deleteButton = new Button(lefttoolbar, SWT.NONE);
deleteButton.setImage(getPluginImage("org.eclipse.ui",
"/icons/full/obj16/delete_obj.gif"));
formToolkit.adapt(deleteButton, true, true);
Button editButton = new Button(lefttoolbar, SWT.NONE);
editButton.setImage(getPluginImage("org.eclipse.ui",
"/icons/full/etool16/editor_area.gif"));
formToolkit.adapt(editButton, true, true);
elementTreeViewer = new TreeViewer(container, SWT.BORDER);
Tree elementTree = elementTreeViewer.getTree();
elementTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
1, 1));
Composite toolbarbox = new Composite(container, 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));
Button selectButton = new Button(toolbarbox, SWT.NONE);
selectButton.setText(">>");
Button deselectButton = new Button(toolbarbox, SWT.NONE);
deselectButton.setText("<<");
selectTreeViewer = new TreeViewer(container, SWT.BORDER);
Tree selectTree = selectTreeViewer.getTree();
selectTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
1, 1));
// create listeners
createButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
createElement();
}
});
deleteButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
deleteElement();
}
});
editButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
editElement();
}
});
selectButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
selectElement();
}
});
deselectButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
deselectElement();
}
});
elementTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
selectElement();
}
});
selectTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
deselectElement();
}
});
// label, content and input
elementTreeViewer.setLabelProvider(new DecorateLabelProvider());
selectTreeViewer.setLabelProvider(new DecorateLabelProvider());
elementTreeViewer.setContentProvider(new MultiRootTreeContentProvider(
rootElements, contentSupport));
selectTreeViewer.setContentProvider(new MultiRootTreeContentProvider(
selectedElements, new EmptyTreeContentProvider()));
elementTreeViewer.setInput(rootElements);
selectTreeViewer.setInput(selectedElements);
// hide edit toolbar if no edit function is available
if (dialogEditSupport == null) {
lefttoolbar.setVisible(false);
((GridData) lefttoolbar.getLayoutData()).exclude = true;
}
return area;
}
/** {@inheritDoc} */
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
false);
createButton(parent, IDialogConstants.CANCEL_ID, "Cancel", true);
}
/** {@inheritDoc} */
@Override
protected Point getInitialSize() {
return new Point(640, 480);
}
/** Returns configuration. */
public IDialogEditSupport getEditSupport() {
return dialogEditSupport;
}
/** 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;
}
/**
* create an element by using the editing module and update the left tree
* viewer
*/
private void createElement() {
if (dialogEditSupport == null)
return;
try {
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() != null
&& selection.getPaths().length != 1)
return; // at most 1 element can be selected
// create the new element
Object o;
if (selection.getPaths() == null) {
o = dialogEditSupport.createElement(null);
} else {
o = dialogEditSupport.createElement(selection.getPaths()[0]
.getLastSegment());
}
if (o == null)
return;
TreePath path;
if (selection.getPaths() == null) {
path = new TreePath(new Object[] { rootElements });
rootElements.add(o);
} else {
path = selection.getPaths()[0];
}
// insert the new element
elementTreeViewer.add(path, o);
} catch (Exception e2) {
e2.printStackTrace();
}
}
/** Call delete function on the selected elements */
private void deleteElement() {
if (dialogEditSupport == null)
return;
try {
// find the path to be deleted
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() == null)
return;
// delete selected elements
for (TreePath path : selection.getPaths()) {
if (dialogEditSupport.deleteElement(path.getLastSegment())) {
if (rootElements.contains(path.getLastSegment()))
rootElements.remove(path.getLastSegment());
elementTreeViewer.remove(path);
for (Object selected : selectedElements.toArray()) {
if (isParent(path.getLastSegment(), selected)) {
selectedElements.remove(selected);
selectTreeViewer.remove(selected);
}
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
/**
* Check whether the given root element is a direct or indirect parent of
* the leaf element
*
* @param root
* the parent
* @param leaf
* the child
* @return true if the root element is a direct or indirect parent of leaf
* element, otherwise false
*/
private boolean isParent(Object root, Object leaf) {
if (root == leaf) {
return true;
}
Object parent = contentSupport.getParent(leaf);
while (parent != null) {
if (parent == root) {
return true;
}
parent = contentSupport.getParent(parent);
}
return false;
}
/** Call edit function on the selected element */
private void editElement() {
if (dialogEditSupport == null) {
return;
}
try {
// find the path to the element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() == null
|| selection.getPaths().length != 1)
return; // 1 element must be selected
TreePath path = selection.getPaths()[0];
dialogEditSupport.editElement(path.getLastSegment());
elementTreeViewer.refresh();
selectTreeViewer.refresh();
} catch (Exception e2) {
e2.printStackTrace();
}
}
/** Add selected elements to the select list. */
private void selectElement() {
try {
// find the path to the element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() == null)
return;
for (TreePath path : selection.getPaths()) {
if (selectedElements.contains(path.getLastSegment()))
continue;
selectedElements.add(path.getLastSegment());
selectTreeViewer.add(selectedElements, path.getLastSegment());
elementTreeViewer.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) selectTreeViewer
.getSelection();
if (selection.getPaths() == null)
return;
for (TreePath path : selection.getPaths()) {
if (selectedElements.remove(path.getLastSegment())) {
selectTreeViewer.remove(path.getLastSegment());
elementTreeViewer.update(path.getLastSegment(), null);
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
\ No newline at end of file
/*--------------------------------------------------------------------------+
$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.OK_ID;
import static org.eclipse.jface.dialogs.IDialogConstants.OK_LABEL;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
/**
* This dialog offers a common dialog to show multi-root tree structures and
* allows user to select one item in the tree. It also offers interface to edit
* the tree on the fly.
*
* TODO shouldn't we move this Dialog to org.fortiss.tooling.base.ui?
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: D56739A3E2352F3C5BE90A37CB7F40F9
*/
public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
/** GUI Factory */
private final FormToolkit formToolkit = new FormToolkit(
Display.getDefault());
/** the editing module */
private IDialogEditSupport dialogEditSupport;
/** the root elements */
private ArrayList<Object> rootElements;
/** the selected element as tree path */
private TreePath selectedPath;
/** the content provider */
private ITreeContentProvider contentSupport;
/** the label provider */
private ILabelProvider labelSupport;
/** the main tree viewer */
private TreeViewer elementTreeViewer;
/**
* Default Constructor for GUI builder.
*
* @param parentShell
*
* @deprecated
* @wbp.parser.constructor
*/
@Deprecated
public ElementTreeSingleSelectDialog(Shell parentShell) {
super(parentShell);
setShellStyle(SWT.SHELL_TRIM);
setErrorMessage("");
setHelpAvailable(false);
}
/**
* Main constructor
*
* @param parentShell
* the parent shell
* @param roots
* the root elements
* @param selected
* the pre-selected element or null
* @param contentProvider
* the content provider
* @param labelProvider
* the label provider
* @param edit
* the editing module or null
*/
public ElementTreeSingleSelectDialog(Shell parentShell, List<?> roots,
Object selected, ITreeContentProvider contentProvider,
ILabelProvider labelProvider, IDialogEditSupport edit) {
super(parentShell);
if (roots == null) {
rootElements = new ArrayList<Object>();
} else {
rootElements = new ArrayList<Object>(roots);
}
if (selected == null) {
selectedPath = null;
} else {
selectedPath = computeTreePath(rootElements, selected);
}
dialogEditSupport = edit;
contentSupport = contentProvider;
labelSupport = labelProvider;
}
/** {@inheritDoc} */
@Override
protected Control createDialogArea(Composite parent) {
// CAUTION: The code below is automatically generated, do not edit
// manually!
setHelpAvailable(false);
setTitle("Select");
setMessage("Select one or more elements");
// create controls
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
GridLayout gl_container = new GridLayout(3, 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;
container.setLayout(gl_container);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite lefttoolbar = new Composite(container, SWT.NONE);
lefttoolbar.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false,
true, 1, 1));
GridLayout gl_lefttoolbar = new GridLayout(1, false);
gl_lefttoolbar.verticalSpacing = 2;
gl_lefttoolbar.horizontalSpacing = 2;
gl_lefttoolbar.marginHeight = 0;
gl_lefttoolbar.marginWidth = 0;
lefttoolbar.setLayout(gl_lefttoolbar);
Button createButton = new Button(lefttoolbar, SWT.NONE);
createButton.setImage(ResourceManager.getPluginImage("org.eclipse.ui",
"/icons/full/obj16/add_obj.gif"));
formToolkit.adapt(createButton, true, true);
Button deleteButton = new Button(lefttoolbar, SWT.NONE);
deleteButton.setImage(ResourceManager.getPluginImage("org.eclipse.ui",
"/icons/full/obj16/delete_obj.gif"));
formToolkit.adapt(deleteButton, true, true);
Button editButton = new Button(lefttoolbar, SWT.NONE);
editButton.setImage(ResourceManager.getPluginImage("org.eclipse.ui",
"/icons/full/etool16/editor_area.gif"));
formToolkit.adapt(editButton, true, true);
elementTreeViewer = new TreeViewer(container, SWT.BORDER);
Tree elementTree = elementTreeViewer.getTree();
elementTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
1, 1));
Composite toolbarbox = new Composite(container, 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));
// create listeners
createButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
createElement();
}
});
deleteButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
deleteElement();
}
});
editButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
editElement();
}
});
elementTreeViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selectElement();
}
});
// label, content and input
elementTreeViewer.setLabelProvider(labelSupport);
elementTreeViewer.setContentProvider(new MultiRootTreeContentProvider(
rootElements, contentSupport));
elementTreeViewer.setInput(rootElements);
if (selectedPath != null)
elementTreeViewer.setSelection(new TreeSelection(selectedPath),
true);
// hide edit toolbar if no edit function is available
if (dialogEditSupport == null) {
lefttoolbar.setVisible(false);
((GridData) lefttoolbar.getLayoutData()).exclude = true;
}
return area;
}
/** {@inheritDoc} */
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, OK_ID, OK_LABEL, false);
createButton(parent, CANCEL_ID, "Cancel", true);
}
/** {@inheritDoc} */
@Override
protected Point getInitialSize() {
return new Point(480, 480);
}
/** Returns configuration. */
public IDialogEditSupport getEditSupport() {
return dialogEditSupport;
}
/** Returns rootElements. */
public List<Object> getRootElements() {
return rootElements;
}
/** Returns selectedElements. */
public Object getSelectedElement() {
if (selectedPath == null)
return null;
return selectedPath.getLastSegment();
}
/** Returns contentSupport. */
public IStructuredContentProvider getContentProvider() {
return contentSupport;
}
/** Returns labelSupport. */
public ILabelProvider getLabelProvider() {
return labelSupport;
}
/** Create an element */
private void createElement() {
if (dialogEditSupport == null)
return;
try {
// find the path to hold the new element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() != null
&& selection.getPaths().length != 1)
return; // at most 1 element can be selected
// create the new element
Object o;
if (selection.getPaths() == null) {
o = dialogEditSupport.createElement(null);
} else {
o = dialogEditSupport.createElement(selection.getPaths()[0]
.getLastSegment());
}
if (o == null)
return;
TreePath path;
if (selection.getPaths() == null) {
path = new TreePath(new Object[] { rootElements });
rootElements.add(o);
} else {
path = selection.getPaths()[0];
}
// insert the new element
elementTreeViewer.add(path, o);
elementTreeViewer.reveal(o);
} catch (Exception e2) {
e2.printStackTrace();
}
}
/** Call delete function on the selected elements */
private void deleteElement() {
if (dialogEditSupport == null)
return;
try {
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() == null)
return;
// delete selected elements
for (TreePath path : selection.getPaths()) {
if (dialogEditSupport.deleteElement(path.getLastSegment())) {
if (rootElements.contains(path.getLastSegment()))
rootElements.remove(path.getLastSegment());
elementTreeViewer.remove(path);
if (path.equals(selectedPath)) {
selectedPath = null;
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
/** Call edit function on the selected element */
private void editElement() {
if (dialogEditSupport == null)
return;
try {
// find the path to the element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() == null
|| selection.getPaths().length != 1)
return; // 1 element must be selected
TreePath path = selection.getPaths()[0];
dialogEditSupport.editElement(path.getLastSegment());
elementTreeViewer.refresh();
} catch (Exception e2) {
e2.printStackTrace();
}
}
/** update the selected element by its tree path */
private void selectElement() {
// find the path to the element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
if (selection.getPaths() == null || selection.getPaths().length != 1) {
selectedPath = null;
getButton(OK_ID).setEnabled(false);
} else {
selectedPath = selection.getPaths()[0];
getButton(OK_ID).setEnabled(true);
}
}
/**
* Create the tree path from one of the given root elements to the child
* element. The content provider will be used to compute the direct parent
* of the given child element.
*
* @param roots
* all possible parent elements
* @param leaf
* the child element
* @return a tree path starting from one of the root elements and up to the
* child element, or null if no such path exists
*/
private TreePath computeTreePath(List<?> roots, Object leaf) {
LinkedList<Object> path = new LinkedList<Object>();
Object parent = leaf;
while (!roots.contains(parent)) {
path.addFirst(parent);
parent = contentSupport.getParent(parent);
if (parent == null)
return null;
}
path.addFirst(parent);
return new TreePath(path.toArray());
}
}
\ No newline at end of file
/*--------------------------------------------------------------------------+
$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;
/**
* Editing interface for {@link ElementTreeSingleSelectDialog} and
* {@link ElementTreeMultiSelectDialog}
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 18119587EF4CCE8667EF38F2C34D6C76
*/
public interface IDialogEditSupport {
/** Return the new element */
public Object createElement(Object selected);
/**
* Delete the element
*
* @param selected
* element to be deleted
* @return true if the element is deleted.
*/
public boolean deleteElement(Object selected);
/** Edit the element */
public void editElement(Object selected);
/**
* Check if element can be created
*
* @return true if a new element can be created, otherwise false
*/
public boolean canCreateElement(Object selected);
/**
* Check if element can be deleted
*
* @return true if the element can be deleted, otherwise false
*/
public boolean canDeleteElement(Object selected);
/**
* Check if element can be edited
*
* @return true if the element can be edited, otherwise false
*/
public boolean canEditElement(Object selected);
}
\ No newline at end of file
/*--------------------------------------------------------------------------+
$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 java.util.Collections;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.fortiss.tooling.base.ui.contentprovider.TreeContentProviderBase;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* {@link ITreeContentProvider} based on {@link IModelElementHandler}. A
* subclass can override the {@link #getChildren(EObject)} method to provide its
* own content.
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 1BA6346E9792B58430211477AC3A31C5
*/
public class ModelElementTreeContentProvider extends TreeContentProviderBase {
/** the root elements */
private final List<? extends EObject> roots;
/** Constructor */
public ModelElementTreeContentProvider(List<? extends EObject> input) {
this.roots = input;
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
if (element instanceof EObject) {
if (roots.contains(element))
return null;
return ((EObject) element).eContainer();
}
return new Object[0];
}
/** {@inheritDoc} */
@Override
public final Object[] getChildren(Object parentElement) {
if (parentElement instanceof EObject) {
return getChildren((EObject) parentElement).toArray();
}
return new Object[0];
}
/**
* Return child {@link EObject}s of the parent {@link EObject} by using
* registered {@link IModelElementHandler}
*/
public List<? extends EObject> getChildren(EObject parentElement) {
IModelElementHandler<EObject> base = IModelElementHandlerService.INSTANCE
.getModelElementHandler(parentElement);
if (base != null) {
return base.getSubnodes(parentElement);
}
return Collections.emptyList();
}
}
\ No newline at end of file
/*--------------------------------------------------------------------------+
$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 java.util.List;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.fortiss.tooling.base.ui.contentprovider.TreeContentProviderBase;
/**
* The adapter content provider which offers contents of a multi-root tree
* according to a normal content provider
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: E68F78BD9B519F8F36D31FC47F68BB02
*/
public class MultiRootTreeContentProvider extends TreeContentProviderBase {
/** the root elements */
private List<Object> roots;
/** the real content provider */
private ITreeContentProvider contentSupport;
/** Constructor */
public MultiRootTreeContentProvider(List<Object> roots,
ITreeContentProvider contentSupport) {
this.roots = roots;
this.contentSupport = contentSupport;
}
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement == roots) {
return roots.toArray();
}
return contentSupport.getChildren(parentElement);
}
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
if (roots.contains(element)) {
return null;
}
return contentSupport.getParent(element);
}
}
\ No newline at end of file
<!--
$Id$
@version $Rev$
@ConQAT.Rating YELLOW Hash: F5BA263532A5969D12FAEEF7BDC9B2AF
-->
<body>
Package for basic dialog classes
</body>
......@@ -30,7 +30,7 @@ import org.eclipse.emf.common.util.EList;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: FFFD8B8B57B4D3099697067E8482441B
* @ConQAT.Rating YELLOW Hash: BF8AC412B3EB14DFA4B48EDE057B394F
*/
public class EcoreUtils {
......@@ -52,9 +52,8 @@ public class EcoreUtils {
}
/**
* From a given EList with source objects of type S create another
* unmodifiable EList with objects of type T, whereby T is a sub-type of S.
* The resulting EList is unmodifiable thereby it represents only a view
* From a given EList create another unmodifiable EList with objects of type
* T. The resulting EList is unmodifiable thereby it represents only a view
* over the source list.
*
* @param targetClass
......@@ -64,12 +63,12 @@ public class EcoreUtils {
* @return an unmodifiable EList of objects of type T
*/
@SuppressWarnings("unchecked")
public static <S, T extends S> EList<T> pickInstanceOf(
Class<T> targetClass, EList<S> sourceList) {
public static <T> EList<T> pickInstanceOf(Class<T> targetClass,
EList<?> sourceList) {
if (sourceList == null)
return null;
EList<T> result = new BasicEList<T>();
for (S sourceElement : sourceList)
for (Object sourceElement : sourceList)
if (targetClass.isAssignableFrom(sourceElement.getClass()))
result.add((T) sourceElement);
return ECollections.unmodifiableEList(result);
......
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