summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMathias Kinzler2010-04-26 12:04:17 (EDT)
committer Chris Aniszczyk2010-04-26 16:20:50 (EDT)
commit9d8b3265b54dd58c4b27fbcc9dc6e4479a062948 (patch)
tree6d71e30b384872294273da2b0fee471457554834
parent51a958c6c1640fe692960d3b0e25e33bc6f5a940 (diff)
downloadegit-9d8b3265b54dd58c4b27fbcc9dc6e4479a062948.zip
egit-9d8b3265b54dd58c4b27fbcc9dc6e4479a062948.tar.gz
egit-9d8b3265b54dd58c4b27fbcc9dc6e4479a062948.tar.bz2
NPE upon Team->Show in Git Repositories Viewrefs/changes/07/607/2
If this action also opens the view for the first time, the refresh won't be finished by the time the action is executed, so there is the NPE described in the bug. Change-Id: I8af99c7689153d1663c039c43eb16f538fcaed19 Bug: 309602 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java104
1 files changed, 67 insertions, 37 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
index 161cb13..68898d6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
@@ -38,7 +38,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.egit.core.op.BranchOperation;
@@ -117,6 +119,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
/** The view ID */
public static final String VIEW_ID = "org.eclipse.egit.ui.RepositoriesView"; //$NON-NLS-1$
+
// TODO central constants? RemoteConfig ones are private
static final String REMOTE = "remote"; //$NON-NLS-1$
@@ -676,8 +679,9 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
@Override
public void widgetSelected(SelectionEvent e) {
- WizardDialog dialog = new WizardDialog(getSite().getShell(),
- new ConfigureRemoteWizard(node.getRepository()));
+ WizardDialog dialog = new WizardDialog(
+ getSite().getShell(), new ConfigureRemoteWizard(
+ node.getRepository()));
if (dialog.open() == Window.OK) {
scheduleRefresh();
}
@@ -697,8 +701,9 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
@Override
public void widgetSelected(SelectionEvent e) {
- WizardDialog dialog = new WizardDialog(getSite().getShell(),
- new ConfigureRemoteWizard(node.getRepository(), name, false));
+ WizardDialog dialog = new WizardDialog(
+ getSite().getShell(), new ConfigureRemoteWizard(
+ node.getRepository(), name, false));
if (dialog.open() == Window.OK) {
scheduleRefresh();
}
@@ -712,8 +717,9 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
@Override
public void widgetSelected(SelectionEvent e) {
- WizardDialog dialog = new WizardDialog(getSite().getShell(),
- new ConfigureRemoteWizard(node.getRepository(), name, true));
+ WizardDialog dialog = new WizardDialog(
+ getSite().getShell(), new ConfigureRemoteWizard(
+ node.getRepository(), name, true));
if (dialog.open() == Window.OK) {
scheduleRefresh();
}
@@ -962,7 +968,8 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
getViewSite().getActionBars().getToolBarManager().add(addAction);
- linkWithSelectionAction = new Action(UIText.RepositoriesView_LinkWithSelection_action,
+ linkWithSelectionAction = new Action(
+ UIText.RepositoriesView_LinkWithSelection_action,
IAction.AS_CHECK_BOX) {
@Override
@@ -984,7 +991,8 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
};
- linkWithSelectionAction.setToolTipText(UIText.RepositoriesView_LinkWithSelection_action);
+ linkWithSelectionAction
+ .setToolTipText(UIText.RepositoriesView_LinkWithSelection_action);
linkWithSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
@@ -1203,7 +1211,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
* TODO exceptions?
*/
@SuppressWarnings("unchecked")
- public void showResource(IResource resource) {
+ public void showResource(final IResource resource) {
IProject project = resource.getProject();
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (mapping == null)
@@ -1211,46 +1219,68 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
if (addDir(mapping.getRepository().getDirectory())) {
scheduleRefresh();
- try {
- scheduledJob.join();
- } catch (InterruptedException e) {
- // ignore here
+ }
+
+ boolean doSetSelection = false;
+
+ if (this.scheduledJob != null) {
+ int state = this.scheduledJob.getState();
+ if (state == Job.WAITING || state == Job.RUNNING) {
+ this.scheduledJob.addJobChangeListener(new JobChangeAdapter() {
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ showResource(resource);
+ }
+ });
+ } else {
+ doSetSelection = true;
}
}
- RepositoriesViewContentProvider cp = (RepositoriesViewContentProvider) tv
- .getContentProvider();
- RepositoryTreeNode currentNode = null;
- Object[] repos = cp.getElements(tv.getInput());
- for (Object repo : repos) {
- RepositoryTreeNode node = (RepositoryTreeNode) repo;
- // TODO equals implementation of Repository?
- if (mapping.getRepository().getDirectory().equals(
- ((Repository) node.getObject()).getDirectory())) {
- for (Object child : cp.getChildren(node)) {
- RepositoryTreeNode childNode = (RepositoryTreeNode) child;
- if (childNode.getType() == RepositoryTreeNodeType.WORKINGDIR) {
+ if (doSetSelection) {
+ RepositoriesViewContentProvider cp = (RepositoriesViewContentProvider) tv
+ .getContentProvider();
+ RepositoryTreeNode currentNode = null;
+ Object[] repos = cp.getElements(tv.getInput());
+ for (Object repo : repos) {
+ RepositoryTreeNode node = (RepositoryTreeNode) repo;
+ // TODO equals implementation of Repository?
+ if (mapping.getRepository().getDirectory().equals(
+ ((Repository) node.getObject()).getDirectory())) {
+ for (Object child : cp.getChildren(node)) {
+ RepositoryTreeNode childNode = (RepositoryTreeNode) child;
+ if (childNode.getType() == RepositoryTreeNodeType.WORKINGDIR) {
+ currentNode = childNode;
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ IPath relPath = new Path(mapping.getRepoRelativePath(resource));
+
+ for (String segment : relPath.segments()) {
+ for (Object child : cp.getChildren(currentNode)) {
+ RepositoryTreeNode<File> childNode = (RepositoryTreeNode<File>) child;
+ if (childNode.getObject().getName().equals(segment)) {
currentNode = childNode;
break;
}
}
- break;
}
- }
- IPath relPath = new Path(mapping.getRepoRelativePath(resource));
+ final RepositoryTreeNode selNode = currentNode;
- for (String segment : relPath.segments()) {
- for (Object child : cp.getChildren(currentNode)) {
- RepositoryTreeNode<File> childNode = (RepositoryTreeNode<File>) child;
- if (childNode.getObject().getName().equals(segment)) {
- currentNode = childNode;
- break;
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ tv.setSelection(new StructuredSelection(selNode), true);
}
- }
- }
+ });
- tv.setSelection(new StructuredSelection(currentNode), true);
+ }
}