Skip to content

Commit

Permalink
Add empty tree functionality to CheckedTreeSelectionDialog (eclipse-p…
Browse files Browse the repository at this point in the history
…latform#1216)

* Add new isEmptyTreeAllowed() method to CheckedTreeSelectionDialog
  • Loading branch information
jjohnstn committed Nov 6, 2023
1 parent 679fbd3 commit 5d3580c
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -82,6 +82,8 @@ public class CheckedTreeSelectionDialog extends SelectionStatusDialog {

private int fStyle = SWT.BORDER;

private final boolean fAllowEmptyTree;

/**
* Constructs an instance of <code>ElementTreeSelectionDialog</code>.
*
Expand All @@ -94,6 +96,20 @@ public CheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider,
this(parent, labelProvider, contentProvider, SWT.BORDER);
}

/**
* Constructs an instance of <code>ElementTreeSelectionDialog</code>.
*
* @param parent The shell to parent from.
* @param labelProvider the label provider to render the entries
* @param contentProvider the content provider to evaluate the tree structure
* @param allowEmptyTree <code>true</code> if an empty tree can be input, <code>false</code> if an empty tree must be treated as an error
* @since 3.131
*/
public CheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider,
boolean allowEmptyTree) {
this(parent, labelProvider, contentProvider, SWT.BORDER, allowEmptyTree);
}

/**
* Constructs an instance of <code>ElementTreeSelectionDialog</code>.
*
Expand All @@ -105,6 +121,23 @@ public CheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider,
*/
public CheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider,
int style) {
this(parent, labelProvider, contentProvider, style, false);
}

/**
* Constructs an instance of <code>ElementTreeSelectionDialog</code>.
*
* @param parent The shell to parent from.
* @param labelProvider the label provider to render the entries
* @param contentProvider the content provider to evaluate the tree structure
* @param style the style of the tree
* @param allowEmptyTree <code>true</code> if an empty tree can be input,
* <code>false</code> if an empty tree must be treated as
* an error
* @since 3.131
*/
public CheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider,
int style, boolean allowEmptyTree) {
super(parent);
fLabelProvider = labelProvider;
fContentProvider = contentProvider;
Expand All @@ -113,6 +146,7 @@ public CheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, IT
fContainerMode = false;
fExpandedElements = null;
fStyle = style;
fAllowEmptyTree = allowEmptyTree;
}

/**
Expand Down Expand Up @@ -241,6 +275,11 @@ protected void updateOKStatus() {
fCurrStatus = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, "", //$NON-NLS-1$
null);
}
} else if (fAllowEmptyTree) {
if (!fCurrStatus.isOK()) {
fCurrStatus = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, "", //$NON-NLS-1$
null);
}
} else {
fCurrStatus = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, fEmptyListMessage, null);
}
Expand Down

0 comments on commit 5d3580c

Please sign in to comment.