Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Projects
Eclipse eTrice™
Eclipse eTrice
Commits
50b6c714
Commit
50b6c714
authored
May 25, 2022
by
Eyrak Paen-Rochlitz
Browse files
[ui.exporter] Only export diagram images if diagram model file exists
parent
77bbfd5a
Pipeline
#4535
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/ExportDiagramsHandler.java
View file @
50b6c714
...
...
@@ -31,6 +31,7 @@ import org.eclipse.core.runtime.IPath;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.core.runtime.NullProgressMonitor
;
import
org.eclipse.core.runtime.Path
;
import
org.eclipse.core.runtime.Platform
;
import
org.eclipse.emf.ecore.EObject
;
import
org.eclipse.etrice.core.room.ActorClass
;
import
org.eclipse.etrice.core.room.RoomModel
;
...
...
@@ -40,6 +41,7 @@ import org.eclipse.etrice.ui.commands.RoomOpeningHelper;
import
org.eclipse.etrice.ui.common.base.UIBaseActivator
;
import
org.eclipse.etrice.ui.common.base.export.IBulkDiagramExporter
;
import
org.eclipse.etrice.ui.common.base.preferences.UIBasePreferenceConstants
;
import
org.eclipse.etrice.ui.common.base.support.DiagramAccessBase
;
import
org.eclipse.jface.dialogs.MessageDialog
;
import
org.eclipse.jface.preference.IPreferenceStore
;
import
org.eclipse.jface.viewers.ISelection
;
...
...
@@ -145,18 +147,27 @@ public class ExportDiagramsHandler extends AbstractHandler {
if
(
folder
.
exists
())
{
String
folderPath
=
folder
.
getLocation
().
toOSString
();
IBulk
Diagram
Exporter
behaviorExporter
=
RoomOpeningHelper
.
getBehaviorDiagramAccess
()
.
getDiagramExporter
()
;
IBulk
Diagram
Exporter
structureExporter
=
RoomOpeningHelper
.
getStructureDiagramAccess
()
.
getDiagramExporter
()
;
Diagram
AccessBase
behaviorDiagramAccess
=
RoomOpeningHelper
.
getBehaviorDiagramAccess
();
Diagram
AccessBase
structureDiagramAccess
=
RoomOpeningHelper
.
getStructureDiagramAccess
();
model
.
getRoomClasses
().
forEach
(
rc
->
{
if
(
rc
instanceof
ActorClass
)
{
ActorClass
ac
=
(
ActorClass
)
rc
;
if
(
ac
.
getStateMachine
()
!=
null
)
{
behaviorExporter
.
export
(
ac
,
folderPath
);
try
{
if
(
rc
instanceof
ActorClass
)
{
ActorClass
ac
=
(
ActorClass
)
rc
;
if
(
ac
.
getStateMachine
()
!=
null
&&
behaviorDiagramAccess
.
diagramExists
(
ac
))
{
behaviorDiagramAccess
.
getDiagramExporter
().
export
(
ac
,
folderPath
);
}
if
(
structureDiagramAccess
.
diagramExists
(
ac
))
{
structureDiagramAccess
.
getDiagramExporter
().
export
(
ac
,
folderPath
);
}
}
else
if
(
rc
instanceof
SubSystemClass
)
{
if
(
structureDiagramAccess
.
diagramExists
(
rc
))
{
structureDiagramAccess
.
getDiagramExporter
().
export
((
SubSystemClass
)
rc
,
folderPath
);
}
}
structureExporter
.
export
(
ac
,
folderPath
);
}
else
if
(
rc
instanceof
SubSystemClass
)
{
structureExporter
.
export
((
SubSystemClass
)
rc
,
folderPath
);
catch
(
Throwable
t
)
{
Platform
.
getLog
(
ExportDiagramsHandler
.
class
).
error
(
"uncaught error in ExportDiagramsHandler for RoomClass '"
+
rc
.
getName
()
+
"'"
,
t
);
}
});
...
...
plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
View file @
50b6c714
...
...
@@ -21,6 +21,7 @@ import java.util.Collections;
import
org.eclipse.core.resources.IFile
;
import
org.eclipse.core.resources.IFolder
;
import
org.eclipse.core.resources.IProject
;
import
org.eclipse.core.resources.IResource
;
import
org.eclipse.core.resources.ResourcesPlugin
;
import
org.eclipse.core.runtime.Path
;
import
org.eclipse.emf.common.command.Command
;
...
...
@@ -79,41 +80,8 @@ public abstract class DiagramAccessBase {
* Load diagram based on rootObjects resource URI into given resourceSet
*/
public
Diagram
getDiagram
(
EObject
rootObject
,
ResourceSet
rs
)
{
Resource
resource
=
rootObject
.
eResource
();
if
(
resource
==
null
)
return
null
;
URI
uri
=
resource
.
getURI
();
URI
diagURI
=
null
;
boolean
exists
=
false
;
if
(
uri
.
isPlatformResource
())
{
uri
=
uri
.
trimSegments
(
1
);
IFolder
diagramFolder
=
null
;
if
(
uri
.
segmentCount
()==
2
)
{
IProject
project
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getProject
(
uri
.
lastSegment
());
diagramFolder
=
project
.
getFolder
(
DIAGRAMS_FOLDER_NAME
);
}
else
{
IFolder
parentFolder
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getFolder
(
new
Path
(
uri
.
toPlatformString
(
true
)));
diagramFolder
=
parentFolder
.
getFolder
(
DIAGRAMS_FOLDER_NAME
);
}
IFile
diagramFile
=
diagramFolder
.
getFile
(
getDigramFileName
(
rootObject
));
diagURI
=
URI
.
createPlatformResourceURI
(
diagramFile
.
getFullPath
().
toString
(),
true
);
exists
=
diagramFile
.
exists
();
}
else
{
File
diagramFile
=
new
File
(
uri
.
toFileString
());
diagramFile
=
new
File
(
diagramFile
.
getParent
()
+
File
.
separator
+
DIAGRAMS_FOLDER_NAME
+
File
.
separator
+
getDigramFileName
(
rootObject
));
diagURI
=
URI
.
createFileURI
(
diagramFile
.
getPath
());
exists
=
diagramFile
.
exists
();
}
if
(
exists
)
{
Resource
diagRes
=
rs
.
getResource
(
diagURI
,
true
);
if
(
diagramExists
(
rootObject
))
{
Resource
diagRes
=
rs
.
getResource
(
getDiagramURI
(
rootObject
),
true
);
if
(
diagRes
.
getContents
().
isEmpty
())
return
null
;
if
(
diagRes
.
getContents
().
get
(
0
)
instanceof
Diagram
)
{
...
...
@@ -123,7 +91,7 @@ public abstract class DiagramAccessBase {
}
}
else
{
Resource
diagRes
=
rs
.
createResource
(
diagURI
);
Resource
diagRes
=
rs
.
createResource
(
getDiagramURI
(
rootObject
)
);
IPreferenceStore
store
=
UIBaseActivator
.
getDefault
().
getPreferenceStore
();
boolean
snap
=
store
.
getBoolean
(
UIBasePreferenceConstants
.
SNAP_TO_GRID
);
...
...
@@ -152,6 +120,55 @@ public abstract class DiagramAccessBase {
return
null
;
}
public
URI
getDiagramURI
(
EObject
rootObject
)
{
Resource
resource
=
rootObject
.
eResource
();
if
(
resource
==
null
)
return
null
;
URI
uri
=
resource
.
getURI
();
URI
diagURI
=
null
;
if
(
uri
.
isPlatformResource
())
{
uri
=
uri
.
trimSegments
(
1
);
IFolder
diagramFolder
=
null
;
if
(
uri
.
segmentCount
()==
2
)
{
IProject
project
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getProject
(
uri
.
lastSegment
());
diagramFolder
=
project
.
getFolder
(
DIAGRAMS_FOLDER_NAME
);
}
else
{
IFolder
parentFolder
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getFolder
(
new
Path
(
uri
.
toPlatformString
(
true
)));
diagramFolder
=
parentFolder
.
getFolder
(
DIAGRAMS_FOLDER_NAME
);
}
IFile
diagramFile
=
diagramFolder
.
getFile
(
getDigramFileName
(
rootObject
));
diagURI
=
URI
.
createPlatformResourceURI
(
diagramFile
.
getFullPath
().
toString
(),
true
);
}
else
{
File
diagramFile
=
new
File
(
uri
.
toFileString
());
diagramFile
=
new
File
(
diagramFile
.
getParent
()
+
File
.
separator
+
DIAGRAMS_FOLDER_NAME
+
File
.
separator
+
getDigramFileName
(
rootObject
));
diagURI
=
URI
.
createFileURI
(
diagramFile
.
getPath
());
}
return
diagURI
;
}
public
boolean
diagramExists
(
EObject
rootObject
)
{
URI
diagURI
=
getDiagramURI
(
rootObject
);
if
(
diagURI
==
null
)
{
return
false
;
}
boolean
exists
=
false
;
if
(
diagURI
.
isPlatformResource
())
{
IResource
diagramFile
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
findMember
(
diagURI
.
toPlatformString
(
true
));
exists
=
(
diagramFile
!=
null
);
}
else
{
File
diagramFile
=
new
File
(
diagURI
.
toFileString
());
exists
=
diagramFile
.
exists
();
}
return
exists
;
}
private
ResourceSet
newResourceSet
(
URI
uri
)
{
if
(
uri
.
isPlatformResource
())
{
IFile
file
=
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getFile
(
new
Path
(
uri
.
toPlatformString
(
true
)));
...
...
@@ -219,6 +236,14 @@ public abstract class DiagramAccessBase {
}
}
/**
* Returns the diagram instance of the corresponding <code>rootObject</code> if the diagram is open in the Workbench.
*
* <p>IMPORTANT: as an additional side effect, if the diagram model does not exist then it will
* automatically be created regardless.</p>
* @param rootObject the model element for the desired diagram
* @return the corresponding diagram instance if it is currently open, or null if it is not open
*/
public
DiagramEditorBase
findDiagramEditor
(
EObject
rootObject
)
{
IFileEditorInput
input
=
getEditorInput
(
rootObject
);
...
...
Write
Preview
Markdown
is supported
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