Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Johann Draschwandtner (Wind River) - [300988] Support filtering variables
*******************************************************************************/
package org.eclipse.debug.ui;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.variables.IDynamicVariable;
import org.eclipse.core.variables.IStringVariable;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.debug.internal.ui.preferences.StringVariablePreferencePage;
import org.eclipse.debug.internal.ui.stringsubstitution.StringSubstitutionMessages;
import org.eclipse.debug.internal.ui.stringsubstitution.StringVariableLabelProvider;
import org.eclipse.debug.internal.ui.stringsubstitution.StringVariablePresentationManager;
import org.eclipse.debug.ui.stringsubstitution.IArgumentSelector;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.osgi.framework.FrameworkUtil;
/**
* A dialog that prompts the user to choose and configure a string
* substitution variable.
*
* Clients may instantiate this class.
*
* @since 3.1
* @noextend This class is not intended to be subclassed by clients.
*/
public class StringVariableSelectionDialog extends ElementListSelectionDialog {
// button to configure variable's argument
private Button fArgumentButton;
// variable description
private Text fDescriptionText;
// the argument value
private Text fArgumentText;
private String fArgumentValue;
private Button fShowAllButton;
private Label fShowAllDescription;
/**
* Base class for custom variable filters. Clients may extend this class
* to filter specific dynamic variables from the selection dialog.
*
* @since 3.6
*/
public static class VariableFilter {
/**
* Returns whether the given variable should be filtered.
*
* @param var variable to be consider
* @return true to filter the variable, otherwise false
*/
public boolean isFiltered(IDynamicVariable var) {
return false;
}
}
//no filtering by default
private final ArrayList fFilters = new ArrayList<>();
//when filtering is on, do not show all by default
private boolean fShowAllSelected = false;
/**
* Constructs a new string substitution variable selection dialog.
*
* @param parent parent shell
*/
public StringVariableSelectionDialog(Shell parent) {
super(parent, new StringVariableLabelProvider());
setShellStyle(getShellStyle() | SWT.RESIZE);
setTitle(StringSubstitutionMessages.StringVariableSelectionDialog_2);
setMessage(StringSubstitutionMessages.StringVariableSelectionDialog_3);
setMultipleSelection(false);
setElements(VariablesPlugin.getDefault().getStringVariableManager().getVariables());
}
/**
* Returns the variable expression the user generated from this
* dialog, or null if none.
*
* @return variable expression the user generated from this
* dialog, or null if none
*/
public String getVariableExpression() {
Object[] selected = getResult();
if (selected != null && selected.length == 1) {
IStringVariable variable = (IStringVariable)selected[0];
StringBuilder buffer = new StringBuilder();
buffer.append("${"); //$NON-NLS-1$
buffer.append(variable.getName());
if (fArgumentValue != null && fArgumentValue.length() > 0) {
buffer.append(":"); //$NON-NLS-1$
buffer.append(fArgumentValue);
}
buffer.append("}"); //$NON-NLS-1$
return buffer.toString();
}
return null;
}
/**
* Add the given variable filter. Has no effect if the given filter has
* already been added. Must be called before the dialog is opened.
*
* @param filter the filter to add
* @since 3.6
*/
public void addVariableFilter(VariableFilter filter) {
if(!fFilters.contains(filter)) {
fFilters.add(filter);
}
}
/**
* Sets the filters, replacing any previous filters.
* Must be called before the dialog is opened.
*
* @param filters
* an array of variable filters, use empty Array or null to reset all Filters.
* @since 3.6
*/
public void setFilters(VariableFilter[] filters) {
fFilters.clear();
if(filters != null && filters.length > 0) {
fFilters.addAll(Arrays.asList(filters));
}
}
private void updateElements() {
final Display display = DebugUIPlugin.getStandardDisplay();
BusyIndicator.showWhile(display, () -> {
final IStringVariable[] elements = VariablesPlugin.getDefault().getStringVariableManager().getVariables();
display.asyncExec(() -> setListElements(elements));
});
}
private void updateDescription() {
if((fShowAllDescription != null) && !fShowAllDescription.isDisposed()) {
if(fShowAllSelected) {
fShowAllDescription.setText(StringSubstitutionMessages.StringVariableSelectionDialog_11);
} else {
fShowAllDescription.setText(StringSubstitutionMessages.StringVariableSelectionDialog_10);
}
}
}
@Override
protected void setListElements(Object[] elements) {
ArrayList