1 /******************************************************************************* 2 * Copyright (c) 2000, 2013 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.debug.ui.actions; 15 16 import java.util.List; 17 18 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; 19 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.SelectionAdapter; 22 import org.eclipse.swt.events.SelectionEvent; 23 import org.eclipse.swt.widgets.Button; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Shell; 26 27 import org.eclipse.jface.viewers.StructuredViewer; 28 29 import org.eclipse.ui.dialogs.ListSelectionDialog; 30 31 import org.eclipse.debug.internal.ui.AbstractDebugCheckboxSelectionDialog; 32 33 import org.eclipse.jdt.core.IJavaProject; 34 35 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 36 37 import org.eclipse.jdt.ui.JavaElementComparator; 38 39 /** 40 * A dialog for selecting projects to add to a classpath or source 41 * lookup path. Optionally specifies whether 42 * exported entries and required projects should also be added. 43 */ 44 public class ProjectSelectionDialog extends AbstractDebugCheckboxSelectionDialog { 45 46 private boolean fAddExportedEntries = true; 47 private boolean fAddRequiredProjects = true; 48 49 private List<IJavaProject> fProjects; 50 51 /** 52 * @param parentShell the parent {@link Shell} 53 * @param projects the list of projects to present 54 * @see ListSelectionDialog 55 */ ProjectSelectionDialog(Shell parentShell, List<IJavaProject> projects)56 public ProjectSelectionDialog(Shell parentShell, List<IJavaProject> projects){ 57 super(parentShell); 58 setShellStyle(getShellStyle() | SWT.RESIZE); 59 setShowSelectAllButtons(true); 60 fProjects = projects; 61 } 62 63 /* (non-Javadoc) 64 * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugCheckboxSelectionDialog#addCustomFooterControls(org.eclipse.swt.widgets.Composite) 65 */ 66 @Override addCustomFooterControls(Composite parent)67 protected void addCustomFooterControls(Composite parent) { 68 super.addCustomFooterControls(parent); 69 final Button addExported = new Button(parent, SWT.CHECK); 70 addExported.setText(ActionMessages.ProjectSelectionDialog_Add_exported_entries_of_selected_projects__1); 71 addExported.addSelectionListener(new SelectionAdapter() { 72 @Override 73 public void widgetSelected(SelectionEvent e) { 74 fAddExportedEntries = addExported.getSelection(); 75 } 76 }); 77 addExported.setSelection(fAddExportedEntries); 78 addExported.setFont(parent.getFont()); 79 80 final Button addRequired = new Button(parent, SWT.CHECK); 81 addRequired.setText(ActionMessages.ProjectSelectionDialog_Add_required_projects_of_selected_projects__2); 82 addRequired.addSelectionListener(new SelectionAdapter() { 83 @Override 84 public void widgetSelected(SelectionEvent e) { 85 fAddRequiredProjects = addRequired.getSelection(); 86 } 87 }); 88 addRequired.setSelection(fAddRequiredProjects); 89 addRequired.setFont(parent.getFont()); 90 } 91 92 /** 93 * Returns whether the user has selected to add exported entries. 94 * 95 * @return whether the user has selected to add exported entries 96 */ isAddExportedEntries()97 public boolean isAddExportedEntries() { 98 return fAddExportedEntries; 99 } 100 101 /** 102 * Returns whether the user has selected to add required projects. 103 * 104 * @return whether the user has selected to add required projects 105 */ isAddRequiredProjects()106 public boolean isAddRequiredProjects() { 107 return fAddRequiredProjects; 108 } 109 110 /* (non-Javadoc) 111 * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getDialogSettingsId() 112 */ 113 @Override getDialogSettingsId()114 protected String getDialogSettingsId() { 115 return IJavaDebugUIConstants.PLUGIN_ID + ".PROJECT_SELECTION_DIALOG_SECTION"; //$NON-NLS-1$ 116 } 117 118 /* (non-Javadoc) 119 * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getHelpContextId() 120 */ 121 @Override getHelpContextId()122 protected String getHelpContextId() { 123 return IJavaDebugHelpContextIds.SELECT_PROJECT_DIALOG; 124 } 125 126 /* (non-Javadoc) 127 * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getViewerInput() 128 */ 129 @Override getViewerInput()130 protected Object getViewerInput() { 131 return fProjects; 132 } 133 134 /* (non-Javadoc) 135 * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#getViewerLabel() 136 */ 137 @Override getViewerLabel()138 protected String getViewerLabel() { 139 return ActionMessages.ProjectSelectionDialog_0; 140 } 141 142 /* 143 * @see org.eclipse.debug.internal.ui.AbstractDebugCheckboxSelectionDialog#createViewer(org.eclipse.swt.widgets.Composite) 144 * @since 3.9 145 */ 146 @Override createViewer(Composite parent)147 protected StructuredViewer createViewer(Composite parent) { 148 StructuredViewer viewer = super.createViewer(parent); 149 viewer.setComparator(new JavaElementComparator()); 150 return viewer; 151 } 152 } 153