-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
174 additions
and
142 deletions.
There are no files selected for viewing
74 changes: 0 additions & 74 deletions
74
modules/PreviewAPI/src/main/java/org/gephi/preview/PreviewWorkspaceDuplicateProvider.java
This file was deleted.
Oops, something went wrong.
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
115 changes: 115 additions & 0 deletions
115
modules/ProjectAPI/src/main/java/org/gephi/project/io/DuplicateTask.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,115 @@ | ||
package org.gephi.project.io; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.PipedInputStream; | ||
import java.io.PipedOutputStream; | ||
import java.util.Collection; | ||
import javax.xml.stream.XMLStreamReader; | ||
import javax.xml.stream.XMLStreamWriter; | ||
import org.gephi.project.api.Workspace; | ||
import org.gephi.project.impl.ProjectImpl; | ||
import org.gephi.project.impl.WorkspaceImpl; | ||
import org.gephi.project.spi.WorkspaceBytesPersistenceProvider; | ||
import org.gephi.project.spi.WorkspacePersistenceProvider; | ||
import org.gephi.project.spi.WorkspaceXMLPersistenceProvider; | ||
import org.gephi.utils.longtask.spi.LongTask; | ||
import org.gephi.utils.progress.Progress; | ||
import org.gephi.utils.progress.ProgressTicket; | ||
import org.openide.util.NbBundle; | ||
|
||
public class DuplicateTask implements LongTask { | ||
|
||
private final Workspace workspace; | ||
|
||
private boolean cancel = false; | ||
|
||
private ProgressTicket progressTicket; | ||
|
||
public DuplicateTask(Workspace workspace) { | ||
this.workspace = workspace; | ||
} | ||
|
||
public WorkspaceImpl run() { | ||
Progress.start(progressTicket); | ||
Progress.setDisplayName(progressTicket, NbBundle.getMessage(DuplicateTask.class, "DuplicateTask.name")); | ||
|
||
try { | ||
WorkspaceImpl newWorkspace = duplicateWorkspace(workspace); | ||
|
||
Collection<WorkspacePersistenceProvider> providers = PersistenceProviderUtils.getPersistenceProviders(); | ||
|
||
for (WorkspacePersistenceProvider provider : providers) { | ||
if (!cancel) { | ||
if (provider instanceof WorkspaceXMLPersistenceProvider) { | ||
duplicateWorkspaceModel(workspace, newWorkspace, (WorkspaceXMLPersistenceProvider) provider); | ||
} else if (provider instanceof WorkspaceBytesPersistenceProvider) { | ||
duplicateWorkspaceModel(workspace, newWorkspace, (WorkspaceBytesPersistenceProvider) provider); | ||
} | ||
} | ||
} | ||
|
||
return newWorkspace; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
Progress.finish(progressTicket); | ||
} | ||
} | ||
|
||
private void duplicateWorkspaceModel(Workspace workspace, Workspace newWorkspace, | ||
WorkspaceBytesPersistenceProvider persistenceProvider) throws Exception { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
DataOutputStream dos = new DataOutputStream(bos); | ||
persistenceProvider.writeBytes(dos, workspace); | ||
bos.close(); | ||
|
||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); | ||
DataInputStream dis = new DataInputStream(bis); | ||
persistenceProvider.readBytes(dis, newWorkspace); | ||
bis.close(); | ||
} | ||
|
||
private void duplicateWorkspaceModel(Workspace workspace, Workspace newWorkspace, | ||
WorkspaceXMLPersistenceProvider persistenceProvider) throws Exception { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
XMLStreamWriter writer = SaveTask.newXMLWriter(bos); | ||
GephiWriter.writeWorkspaceChildren(writer, workspace, persistenceProvider); | ||
writer.close(); | ||
bos.close(); | ||
|
||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); | ||
XMLStreamReader reader = LoadTask.newXMLReader(bis); | ||
GephiReader.readWorkspaceChildren(newWorkspace, reader, persistenceProvider); | ||
reader.close(); | ||
bis.close(); | ||
} | ||
|
||
private WorkspaceImpl duplicateWorkspace(Workspace workspace) throws Exception { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
XMLStreamWriter writer = SaveTask.newXMLWriter(bos); | ||
GephiWriter.writeWorkspace(writer, workspace); | ||
writer.close(); | ||
bos.flush(); | ||
|
||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); | ||
XMLStreamReader reader = LoadTask.newXMLReader(bis); | ||
WorkspaceImpl newWorkspace = GephiReader.readWorkspace(reader, (ProjectImpl) workspace.getProject()); | ||
reader.close(); | ||
bis.close(); | ||
return newWorkspace; | ||
} | ||
|
||
@Override | ||
public boolean cancel() { | ||
cancel = true; | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setProgressTicket(ProgressTicket progressTicket) { | ||
this.progressTicket = progressTicket; | ||
} | ||
} |
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: 0 additions & 58 deletions
58
modules/ProjectAPI/src/main/java/org/gephi/project/spi/WorkspaceDuplicateProvider.java
This file was deleted.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
modules/ProjectAPI/src/main/resources/org/gephi/project/impl/Bundle.properties
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Services/MIMEResolver/GephiResolver.xml=Gephi Files | ||
Templates/Other/GephiTemplate.gephi=Empty Gephi file | ||
Project.default.prefix=Untitled | ||
Workspace.default.prefix=Workspace | ||
Workspace.default.prefix=Workspace | ||
Workspace.duplicated.name=Copy of {0} |
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
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