-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-2196: Projects are now imported correctly
- Loading branch information
Showing
4 changed files
with
100 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
ui/src/main/java/org/jboss/forge/netbeans/ui/listener/ProjectImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2015 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* JBoss by Red Hat - initial API and implementation and/or initial documentation | ||
*/ | ||
package org.jboss.forge.netbeans.ui.listener; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
import org.jboss.forge.addon.projects.Project; | ||
import org.netbeans.api.project.ProjectManager; | ||
import org.netbeans.api.project.ui.OpenProjects; | ||
import org.openide.filesystems.FileObject; | ||
import org.openide.filesystems.FileUtil; | ||
import org.openide.util.Exceptions; | ||
|
||
/** | ||
* Queues projects and allows to import at a later stage | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public enum ProjectImporter { | ||
|
||
INSTANCE; | ||
|
||
private final Queue<Project> projects = new LinkedList<>(); | ||
|
||
public void addProject(Project project) { | ||
projects.add(project); | ||
} | ||
|
||
public void importProjects() { | ||
while (projects.size() > 0) { | ||
doImport(projects.poll()); | ||
} | ||
} | ||
|
||
private void doImport(Project project) { | ||
File root = (File) project.getRoot().getUnderlyingResourceObject(); | ||
FileObject dir = FileUtil.toFileObject(root); | ||
try { | ||
org.netbeans.api.project.Project p = ProjectManager.getDefault().findProject(dir); | ||
OpenProjects.getDefault().open(new org.netbeans.api.project.Project[]{p}, true, true); | ||
} catch (IOException | IllegalArgumentException ex) { | ||
Exceptions.printStackTrace(ex); | ||
} | ||
} | ||
|
||
public void clear() { | ||
projects.clear(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...in/java/org/jboss/forge/netbeans/ui/listener/ProjectImporterCommandExecutionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2015 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* JBoss by Red Hat - initial API and implementation and/or initial documentation | ||
*/ | ||
package org.jboss.forge.netbeans.ui.listener; | ||
|
||
import org.jboss.forge.addon.ui.command.CommandExecutionListener; | ||
import org.jboss.forge.addon.ui.command.UICommand; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public enum ProjectImporterCommandExecutionListener implements CommandExecutionListener { | ||
INSTANCE; | ||
|
||
@Override | ||
public void preCommandExecuted(UICommand command, UIExecutionContext context) { | ||
} | ||
|
||
@Override | ||
public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { | ||
ProjectImporter.INSTANCE.importProjects(); | ||
} | ||
|
||
@Override | ||
public void postCommandFailure(UICommand command, UIExecutionContext context, Throwable failure) { | ||
ProjectImporter.INSTANCE.clear(); | ||
} | ||
|
||
|
||
} |