Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
d86724f5
Commit
d86724f5
authored
Jul 02, 2013
by
Christoph Döbber
Browse files
finished import export of external references
refs 1007
parent
8986d291
Changes
4
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.project.ui/trunk/src/org/fortiss/af3/project/ui/utils/ExportProjectUtils.java
View file @
d86724f5
...
...
@@ -40,6 +40,7 @@ import org.fortiss.af3.project.AF3ProjectActivator;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.project.model.impl.FileProjectImpl
;
import
org.fortiss.af3.project.storage.LocationProvider
;
import
org.fortiss.af3.project.utils.ExternalFileUtils
;
/**
* Utility class providing import- and export-tools for file based projects.
...
...
@@ -103,15 +104,18 @@ public class ExportProjectUtils {
*
* @param project
* the {@link FileProject} that should be exported
* @param
p
ath
* @param
targetP
ath
* the {@link URI} location at which the project should be
* exported
*/
public
static
void
exportProject
(
FileProject
project
,
URI
p
ath
)
{
public
static
void
exportProject
(
FileProject
project
,
URI
sourcePath
,
URI
targetP
ath
)
{
try
{
Resource
r
=
new
ResourceSetImpl
().
createResource
(
p
ath
);
Resource
r
=
new
ResourceSetImpl
().
createResource
(
targetP
ath
);
r
.
getContents
().
add
(
project
);
r
.
save
(
buildOptionsMap
());
// Copy referenced external documents along accordingly.
ExternalFileUtils
.
copyExternalReferences
(
project
,
sourcePath
,
targetPath
);
}
catch
(
IOException
e
)
{
error
(
AF3ProjectActivator
.
getDefault
(),
"File cannot be exported!"
,
e
);
e
.
printStackTrace
();
...
...
org.fortiss.af3.project.ui/trunk/src/org/fortiss/af3/project/ui/utils/ImportProjectUtils.java
View file @
d86724f5
...
...
@@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.FileDialog;
import
org.eclipse.swt.widgets.Shell
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.project.storage.LocationProvider
;
import
org.fortiss.af3.project.utils.ExternalFileUtils
;
/**
* Utility methods for importing projects into workspace.
...
...
@@ -156,6 +157,10 @@ public class ImportProjectUtils {
targetResource
.
getContents
().
add
(
sourceFileProject
);
targetResource
.
save
(
buildOptionsMap
());
// Copy referenced external documents along accordingly.
ExternalFileUtils
.
copyExternalReferences
(
sourceFileProject
,
sourceFileURI
,
targetFileURI
);
}
catch
(
Exception
e
)
{
error
(
getDefault
(),
"Error, cannot import AF3 project!"
,
e
);
openError
(
Display
.
getDefault
().
getActiveShell
(),
"Error, cannot import AF3 project!"
,
...
...
org.fortiss.af3.project/trunk/src/org/fortiss/af3/project/utils/ExternalFileUtils.java
View file @
d86724f5
...
...
@@ -21,13 +21,13 @@ import java.io.File;
import
java.io.IOException
;
import
org.conqat.lib.commons.filesystem.FileSystemUtils
;
import
org.eclipse.core.resources.ResourcesPlugin
;
import
org.eclipse.core.runtime.IPath
;
import
org.eclipse.emf.common.util.TreeIterator
;
import
org.eclipse.emf.common.util.URI
;
import
org.eclipse.emf.ecore.EObject
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.tooling.kernel.ToolingKernelActivator
;
import
org.fortiss.tooling.kernel.model.IExternalDocumentReference
;
import
org.fortiss.tooling.kernel.utils.LoggingUtils
;
/**
*
...
...
@@ -39,10 +39,10 @@ import org.fortiss.tooling.kernel.utils.LoggingUtils;
public
class
ExternalFileUtils
{
/**
* C
heck given e-object and all its children for {@link IE
xternal
D
ocument
R
eference
}
*
* C
opies along all e
xternal
d
ocument
s r
eference
d relatively through
*
{@link IExternalDocumentReference}
*/
public
static
void
c
heckImportedFile
References
(
FileProject
fileProject
,
URI
sourceFileURI
,
public
static
void
c
opyExternal
References
(
FileProject
fileProject
,
URI
sourceFileURI
,
URI
targetFileURI
)
{
TreeIterator
<
EObject
>
currentContents
=
fileProject
.
eAllContents
();
...
...
@@ -52,19 +52,28 @@ public class ExternalFileUtils {
if
(
current
instanceof
IExternalDocumentReference
)
{
IExternalDocumentReference
ref
=
(
IExternalDocumentReference
)
current
;
File
sourcePath
=
new
File
(
sourceFileURI
.
path
()).
getParentFile
().
getAbsoluteFile
();
File
sourcePath
;
if
(
sourceFileURI
.
isPlatformResource
())
{
IPath
workspace
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getLocation
();
sourcePath
=
new
File
(
workspace
.
toFile
(),
sourceFileURI
.
toPlatformString
(
false
))
.
getParentFile
();
}
else
{
sourcePath
=
new
File
(
sourceFileURI
.
path
()).
getParentFile
();
}
File
destinationPath
=
new
File
(
targetFileURI
.
path
()).
getParentFile
().
getAbsoluteFile
();
File
sourceFile
=
new
File
(
sourcePath
,
ref
.
getUri
());
if
(!
sourceFile
.
exists
())
{
LoggingUtils
.
warning
(
ToolingKernelActivator
.
getDefault
(),
"Could not load "
+
ref
.
getUri
());
// possibly hyperlink
continue
;
}
// c
heck file type
// c
opy
try
{
FileSystemUtils
.
copyFile
(
sourceFile
,
new
File
(
destinationPath
,
ref
.
getUri
()));
}
catch
(
IOException
e
)
{
...
...
org.fortiss.af3.rcp.application/trunk/src/org/fortiss/af3/rcp/application/handler/ApplicationCommandHandler.java
View file @
d86724f5
...
...
@@ -301,7 +301,8 @@ public class ApplicationCommandHandler {
/**
* Handles the command action to create the Test Specific Example Action
*/
public
static
final
class
LoadSimpleTrafficLightsTestSpecificExampleCommandHandler
extends
AbstractHandler
{
public
static
final
class
LoadSimpleTrafficLightsTestSpecificExampleCommandHandler
extends
AbstractHandler
{
/** {@inheritDoc} */
@Override
...
...
@@ -500,7 +501,9 @@ public class ApplicationCommandHandler {
if
(
exportFileLocation
!=
null
)
{
// Use copy to avoid error 'Cannot modify resource set
// without a write transaction'.
ExportProjectUtils
.
exportProject
(
EcoreUtil
.
copy
(
selectedProject
),
selectedProject
.
eResource
().
getURI
(),
URI
.
createFileURI
(
exportFileLocation
));
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment