|
17 | 17 | *******************************************************************************/
|
18 | 18 | package io.sloeber.autoBuild.ui.tabs;
|
19 | 19 |
|
| 20 | +import static io.sloeber.autoBuild.helpers.api.AutoBuildConstants.*; |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.Set; |
| 23 | +import java.util.TreeSet; |
| 24 | + |
| 25 | +import javax.swing.JFrame; |
| 26 | +import javax.swing.JOptionPane; |
| 27 | + |
20 | 28 | import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
| 29 | +import org.eclipse.swt.SWT; |
21 | 30 | import org.eclipse.swt.events.SelectionEvent;
|
22 | 31 | import org.eclipse.swt.events.SelectionListener;
|
23 | 32 | import org.eclipse.swt.layout.GridData;
|
24 | 33 | import org.eclipse.swt.layout.GridLayout;
|
25 | 34 | import org.eclipse.swt.widgets.Button;
|
26 | 35 | import org.eclipse.swt.widgets.Composite;
|
27 | 36 | import org.eclipse.swt.widgets.Group;
|
| 37 | +import org.eclipse.swt.widgets.List; |
| 38 | + |
28 | 39 | import io.sloeber.autoBuild.ui.internal.Messages;
|
29 | 40 |
|
30 | 41 | /**
|
|
33 | 44 | */
|
34 | 45 | public class TeamSharedTab extends AbstractAutoBuildPropertyTab {
|
35 | 46 |
|
36 |
| - private Button myShareConfigButton; |
37 |
| - |
38 |
| - @Override |
39 |
| - public void createControls(Composite parent) { |
40 |
| - super.createControls(parent); |
41 |
| - usercomp.setLayout(new GridLayout(1, false)); |
42 |
| - |
43 |
| - // Builder group |
44 |
| - Group g1 = setupGroup(usercomp, Messages.ShareConfigTitle, 3, GridData.FILL_HORIZONTAL); |
45 |
| - myShareConfigButton = setupCheck(g1, Messages.shareConfigButton, 3, GridData.BEGINNING); |
46 |
| - myShareConfigButton.addSelectionListener(new SelectionListener() { |
47 |
| - |
48 |
| - @Override |
49 |
| - public void widgetSelected(SelectionEvent e) { |
50 |
| - myAutoConfDesc.setTeamShared(myShareConfigButton.getSelection()); |
51 |
| - updateButtons(); |
52 |
| - } |
53 |
| - |
54 |
| - @Override |
55 |
| - public void widgetDefaultSelected(SelectionEvent e) { |
56 |
| - // TODO Auto-generated method stub |
57 |
| - return; |
58 |
| - } |
59 |
| - }); |
60 |
| - |
61 |
| - } |
62 |
| - |
63 |
| - private void updateDisplayedData() { |
64 |
| - myShareConfigButton.setSelection(myAutoConfDesc.isTeamShared()); |
65 |
| - } |
66 |
| - |
67 |
| - @Override |
68 |
| - public void updateData(ICResourceDescription cfgd) { |
69 |
| - super.updateData(cfgd); |
70 |
| - updateDisplayedData(); |
71 |
| - } |
72 |
| - |
73 |
| - /** |
74 |
| - * sets widgets states |
75 |
| - */ |
76 |
| - @Override |
77 |
| - protected void updateButtons() { |
78 |
| - myShareConfigButton.setSelection(myAutoConfDesc.isTeamShared()); |
79 |
| - } |
80 |
| - |
81 |
| - |
82 |
| - // This page can be displayed for project only |
83 |
| - @Override |
84 |
| - public boolean canBeVisible() { |
85 |
| - return page.isForProject() || page.isForPrefs(); |
86 |
| - } |
87 |
| - |
88 |
| - @Override |
89 |
| - protected void performDefaults() { |
90 |
| - myShareConfigButton.setSelection(false); |
91 |
| - } |
| 47 | + private Button myShareConfigButton; |
| 48 | + private List myExclusions; |
| 49 | + private Button myAddExclusionButton; |
| 50 | + private Button myRemoveExclusionButton; |
| 51 | + |
| 52 | + @Override |
| 53 | + public void createControls(Composite parent) { |
| 54 | + super.createControls(parent); |
| 55 | + usercomp.setLayout(new GridLayout(1, false)); |
| 56 | + |
| 57 | + // Builder group |
| 58 | + Group g1 = setupGroup(usercomp, Messages.ShareConfigTitle, 2, |
| 59 | + GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); |
| 60 | + myShareConfigButton = setupCheck(g1, Messages.shareConfigButton, 2, GridData.BEGINNING); |
| 61 | + Group g3 = setupGroup(g1, EMPTY_STR, 1, SWT.FILL | GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); |
| 62 | + myExclusions = new List(g3, GridData.FILL_BOTH); |
| 63 | + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
| 64 | + myExclusions.setLayoutData(gridData); |
| 65 | + Group g4 = setupGroup(g1, EMPTY_STR, 1, GridData.VERTICAL_ALIGN_BEGINNING); |
| 66 | + |
| 67 | + int mode = GridData.BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING; |
| 68 | + myAddExclusionButton = setupButton(g4, Messages.addExclusion, 1, mode); |
| 69 | + myRemoveExclusionButton = setupButton(g4, Messages.removeExclusion, 1, mode); |
| 70 | + myExclusions.addSelectionListener(new SelectionListener() { |
| 71 | + |
| 72 | + @Override |
| 73 | + public void widgetSelected(SelectionEvent e) { |
| 74 | + myRemoveExclusionButton.setEnabled(myExclusions.getSelectionCount() > 0); |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public void widgetDefaultSelected(SelectionEvent e) { |
| 80 | + // Nothing to be done |
| 81 | + |
| 82 | + } |
| 83 | + }); |
| 84 | + myShareConfigButton.addSelectionListener(new SelectionListener() { |
| 85 | + |
| 86 | + @Override |
| 87 | + public void widgetSelected(SelectionEvent e) { |
| 88 | + myAutoConfDesc.setTeamShared(myShareConfigButton.getSelection()); |
| 89 | + updateButtons(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public void widgetDefaultSelected(SelectionEvent e) { |
| 94 | + return; |
| 95 | + } |
| 96 | + }); |
| 97 | + |
| 98 | + myRemoveExclusionButton.addSelectionListener(new SelectionListener() { |
| 99 | + |
| 100 | + @Override |
| 101 | + public void widgetSelected(SelectionEvent e) { |
| 102 | + String[] selected = myExclusions.getSelection(); |
| 103 | + if (selected.length == 0) { |
| 104 | + return; |
| 105 | + } |
| 106 | + Set<String> allItem = new TreeSet<>(Arrays.asList(myExclusions.getItems())); |
| 107 | + allItem.removeAll(Arrays.asList(selected)); |
| 108 | + myAutoConfDesc.setCustomTeamExclusionKeys(allItem); |
| 109 | + updateDisplayedData(); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public void widgetDefaultSelected(SelectionEvent e) { |
| 114 | + // Nothing to be done |
| 115 | + } |
| 116 | + }); |
| 117 | + |
| 118 | + myAddExclusionButton.addSelectionListener(new SelectionListener() { |
| 119 | + |
| 120 | + @Override |
| 121 | + public void widgetSelected(SelectionEvent e) { |
| 122 | + JFrame frame = new JFrame(); |
| 123 | + String text = JOptionPane.showInputDialog(frame, Messages.ProvideExclusionKey); |
| 124 | + if (text != null) { |
| 125 | + Set<String> exclusiosn = getCustomTeamExclusionKeys(); |
| 126 | + exclusiosn.add(text); |
| 127 | + myAutoConfDesc.setCustomTeamExclusionKeys(exclusiosn); |
| 128 | + updateDisplayedData(); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public void widgetDefaultSelected(SelectionEvent e) { |
| 134 | + // nothing to do her |
| 135 | + } |
| 136 | + }); |
| 137 | + } |
| 138 | + |
| 139 | + private void updateDisplayedData() { |
| 140 | + boolean isShared = myAutoConfDesc.isTeamShared(); |
| 141 | + myShareConfigButton.setSelection(isShared); |
| 142 | + myAddExclusionButton.setEnabled(isShared); |
| 143 | + myExclusions.setEnabled(isShared); |
| 144 | + myExclusions.removeAll(); |
| 145 | + if (isShared) { |
| 146 | + String prefix=myAutoConfDesc.getCdtConfigurationDescription().getName()+DOT; |
| 147 | + Set<String> exclusions = getCustomTeamExclusionKeys(); |
| 148 | + for (String curExclusion : exclusions) { |
| 149 | + myExclusions.add(prefix+curExclusion); |
| 150 | + } |
| 151 | + myRemoveExclusionButton.setEnabled(myExclusions.getSelectionCount() > 0); |
| 152 | + } else { |
| 153 | + myRemoveExclusionButton.setEnabled(isShared); |
| 154 | + |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + private Set<String> getCustomTeamExclusionKeys() { |
| 159 | + Set<String> ret = myAutoConfDesc.getCustomTeamExclusionKeys(); |
| 160 | + if (ret == null) { |
| 161 | + ret = myAutoConfDesc.getDefaultTeamExclusionKeys(); |
| 162 | + } |
| 163 | + return ret; |
| 164 | + } |
| 165 | + |
| 166 | + @Override |
| 167 | + public void updateData(ICResourceDescription cfgd) { |
| 168 | + super.updateData(cfgd); |
| 169 | + updateDisplayedData(); |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * sets widgets states |
| 174 | + */ |
| 175 | + @Override |
| 176 | + protected void updateButtons() { |
| 177 | + updateDisplayedData(); |
| 178 | + } |
| 179 | + |
| 180 | + // This page can be displayed for project only |
| 181 | + @Override |
| 182 | + public boolean canBeVisible() { |
| 183 | + return page.isForProject() || page.isForPrefs(); |
| 184 | + } |
| 185 | + |
| 186 | + @Override |
| 187 | + protected void performDefaults() { |
| 188 | + myAutoConfDesc.setTeamShared(false); |
| 189 | + myAutoConfDesc.setCustomTeamExclusionKeys(null); |
| 190 | + updateDisplayedData(); |
| 191 | + } |
92 | 192 |
|
93 | 193 | }
|
0 commit comments