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

bug partially fixed

refs 394
parent ec7bd9ea
No related branches found
No related tags found
No related merge requests found
......@@ -17,9 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
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;
......@@ -34,7 +32,6 @@ 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;
......@@ -52,7 +49,7 @@ import org.eclipse.swt.widgets.Shell;
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 1F1AEE709062AF84FC45A41E95D67DBD
* @ConQAT.Rating YELLOW Hash: 21390B2073FFC2212901CC3D583D88DA
*/
public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
......@@ -71,24 +68,8 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
/** 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);
}
/** The gui composite */
private ElementTreeSingleSelectDialogGUI gui;
/**
* Main constructor
......@@ -117,23 +98,20 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
rootElements = new ArrayList<Object>(roots);
}
dialogEditSupport = edit;
contentSupport = contentProvider;
labelSupport = labelProvider;
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");
......@@ -141,30 +119,45 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
// create controls
Composite area = (Composite) super.createDialogArea(parent);
ElementTreeSingleSelectDialogGUI container = new ElementTreeSingleSelectDialogGUI(
area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
gui = new ElementTreeSingleSelectDialogGUI(area, SWT.NONE);
gui.setLayoutData(new GridData(GridData.FILL_BOTH));
// hide edit toolbar if no edit function is available
if (dialogEditSupport == null) {
gui.getLeftToolBar().setVisible(false);
((GridData) gui.getLeftToolBar().getLayoutData()).exclude = true;
}
// label, content and input
gui.getElementTreeViewer().setLabelProvider(labelSupport);
gui.getElementTreeViewer().setContentProvider(
new MultiRootTreeContentProvider(rootElements, contentSupport));
gui.getElementTreeViewer().setInput(rootElements);
if (selectedPath != null)
gui.getElementTreeViewer().setSelection(
new TreeSelection(selectedPath), true);
// create listeners
container.getCreateButton().addSelectionListener(
new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
createElement();
}
});
gui.getCreateButton().addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
createElement();
}
});
container.getDeleteButton().addSelectionListener(
new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
deleteElement();
}
});
gui.getDeleteButton().addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
deleteElement();
}
});
container.getEditButton().addSelectionListener(new SelectionAdapter() {
gui.getEditButton().addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
......@@ -172,42 +165,17 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
}
});
elementTreeViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
gui.getElementTreeViewer().addPostSelectionChangedListener(
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) {
container.getLeftToolBar().setVisible(false);
((GridData) container.getLeftToolBar().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() {
......@@ -249,8 +217,8 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
try {
// find the path to hold the new element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
ITreeSelection selection = (ITreeSelection) gui
.getElementTreeViewer().getSelection();
if (selection.getPaths() != null
&& selection.getPaths().length != 1)
return; // at most 1 element can be selected
......@@ -275,8 +243,8 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
}
// insert the new element
elementTreeViewer.add(path, o);
elementTreeViewer.reveal(o);
gui.getElementTreeViewer().add(path, o);
gui.getElementTreeViewer().reveal(o);
} catch (Exception e2) {
e2.printStackTrace();
}
......@@ -288,8 +256,8 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
return;
try {
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
ITreeSelection selection = (ITreeSelection) gui
.getElementTreeViewer().getSelection();
if (selection.getPaths() == null)
return;
......@@ -299,7 +267,7 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
if (rootElements.contains(path.getLastSegment()))
rootElements.remove(path.getLastSegment());
elementTreeViewer.remove(path);
gui.getElementTreeViewer().remove(path);
if (path.equals(selectedPath)) {
selectedPath = null;
......@@ -318,8 +286,8 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
try {
// find the path to the element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
.getSelection();
ITreeSelection selection = (ITreeSelection) gui
.getElementTreeViewer().getSelection();
if (selection.getPaths() == null
|| selection.getPaths().length != 1)
return; // 1 element must be selected
......@@ -327,7 +295,7 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
TreePath path = selection.getPaths()[0];
dialogEditSupport.editElement(path.getLastSegment());
elementTreeViewer.refresh();
gui.getElementTreeViewer().refresh();
} catch (Exception e2) {
e2.printStackTrace();
}
......@@ -336,7 +304,7 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
/** update the selected element by its tree path */
private void selectElement() {
// find the path to the element
ITreeSelection selection = (ITreeSelection) elementTreeViewer
ITreeSelection selection = (ITreeSelection) gui.getElementTreeViewer()
.getSelection();
if (selection.getPaths() == null || selection.getPaths().length != 1) {
selectedPath = null;
......
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