Skip to content

Commit

Permalink
513306: Propose solutions for missing natures
Browse files Browse the repository at this point in the history
Show natures with proposals as check list instead of text labels
- Make nature proposals selectable
- TODO: "Don't ask again" and preference list for ignored natures

Bug: 513306
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=513306
  • Loading branch information
creckord committed Jun 14, 2017
1 parent d24c5e1 commit 3bd861f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean visit(IResourceDelta delta) throws CoreException {
return false;
}
for (String natureId : project.getDescription().getNatureIds()) {
if (project.getWorkspace().getNatureDescriptor(natureId) == null) {
if (true || project.getWorkspace().getNatureDescriptor(natureId) == null) {
this.missingNatures.add(natureId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
package org.eclipse.epp.internal.mpc.ui.discovery;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Set;

import org.eclipse.epp.internal.mpc.ui.Messages;
import org.eclipse.epp.internal.mpc.ui.preferences.ProjectNaturesPreferencePage;
Expand All @@ -25,10 +25,16 @@
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
Expand All @@ -41,9 +47,14 @@ final class ShowNatureProposalsDialog extends TitleAreaDialog {

private final Map<String, Collection<INode>> candidates;

private CheckboxTableViewer naturesCheckList;

private final Set<String> selectedNatures;

ShowNatureProposalsDialog(Shell parentShell, Map<String, Collection<INode>> candidates) {
super(parentShell);
this.candidates = candidates;
this.selectedNatures = new LinkedHashSet<String>(candidates.keySet());
}

@Override
Expand All @@ -67,16 +78,32 @@ public Control createDialogArea(Composite parent) {
.applyTo(res);
GridLayoutFactory.fillDefaults().margins(LayoutConstants.getMargins()).equalWidth(false).applyTo(
res);

Label label = new Label(res, SWT.WRAP);
StringBuilder message = new StringBuilder(Messages.MissingNatureDetector_Message);
message.append("\n\n"); //$NON-NLS-1$
SortedSet<String> relevantNatures = new TreeSet<String>(candidates.keySet());
for (String natureId : relevantNatures) {
message.append("- "); //$NON-NLS-1$
message.append(natureId);
message.append('\n');
}
label.setText(message.toString());
label.setText(Messages.MissingNatureDetector_Message);

naturesCheckList = CheckboxTableViewer.newCheckList(res,
SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
naturesCheckList.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
return ((Set<?>) inputElement).toArray();
}
});
naturesCheckList.setComparator(new ViewerComparator());
naturesCheckList.setInput(candidates.keySet());
naturesCheckList.setAllChecked(true);
GridDataFactory.fillDefaults().applyTo(naturesCheckList.getControl());
naturesCheckList.addCheckStateListener(new ICheckStateListener() {

public void checkStateChanged(CheckStateChangedEvent event) {
Button okButton = getButton(IDialogConstants.OK_ID);
if (okButton != null) {
okButton.setEnabled(canComplete());
}
updateSelectedNatures();
}
});

Link preferencesLink = new Link(res, SWT.NONE);
preferencesLink.setText(Messages.MissingNatureDetector_linkToPreferences);
preferencesLink.addSelectionListener(new SelectionAdapter() {
Expand All @@ -91,17 +118,40 @@ public void widgetSelected(SelectionEvent e) {
return res;
}

private void updateSelectedNatures() {
selectedNatures.clear();
Object[] checkedElements = naturesCheckList.getCheckedElements();
if (checkedElements == null) {
return;
}
for (Object selected : checkedElements) {
selectedNatures.add(selected.toString());
}
}

@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.OK_ID).setText(Messages.MissingNatureDetector_ShowSolutions);
Button okButton = getButton(IDialogConstants.OK_ID);
okButton.setText(Messages.MissingNatureDetector_ShowSolutions);
okButton.setEnabled(canComplete());
}

protected boolean canComplete() {
Object[] checkedElements = naturesCheckList.getCheckedElements();
return checkedElements != null && checkedElements.length > 0;
}

@Override
public boolean close() {
updateSelectedNatures();
if (super.close()) {
wizban.dispose();
}
return false;
}

public Set<String> getSelectedNatures() {
return selectedNatures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.epp.mpc.ui.IMarketplaceClientService;
import org.eclipse.epp.mpc.ui.MarketplaceClient;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.UIJob;

Expand All @@ -38,18 +37,21 @@ final class ShowNatureProposalsJob extends UIJob {

@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
TitleAreaDialog dialog = new ShowNatureProposalsDialog(
ShowNatureProposalsDialog dialog = new ShowNatureProposalsDialog(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), candidates);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return Status.CANCEL_STATUS;
}
Set<String> natureIds = dialog.getSelectedNatures();
IMarketplaceClientService marketplaceClientService = MarketplaceClient.getMarketplaceClientService();
IMarketplaceClientConfiguration config = marketplaceClientService.newConfiguration();
Set<INode> allNodes = new HashSet<INode>();
for (Collection<INode> candidateNodes : candidates.values()) {
allNodes.addAll(candidateNodes);
for (String natureId : natureIds) {
allNodes.addAll(candidates.get(natureId));
}
if (!allNodes.isEmpty()) {
marketplaceClientService.open(config, allNodes);
}
marketplaceClientService.open(config, allNodes);
return Status.OK_STATUS;
}
}

0 comments on commit 3bd861f

Please sign in to comment.