Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 346172 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/sapphire-extension.xml (+48 lines)
Lines 12-17 Link Here
12
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
12
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
13
 *    Gregory Amerson - [358295] Need access to selection in list property editor
13
 *    Gregory Amerson - [358295] Need access to selection in list property editor
14
 *    Gregory Amerson - [377136] Add Sapphire.Diagram.Node to possible contexts for Sapphire.Add  
14
 *    Gregory Amerson - [377136] Add Sapphire.Diagram.Node to possible contexts for Sapphire.Add  
15
 *    Gregory Amerson - [346172] [diagram] Add print, zoom, save as image actions  
15
 ******************************************************************************
16
 ******************************************************************************
16
-->
17
-->
17
18
Lines 216-221 Link Here
216
        <group>Sapphire.Diagram.Appearance</group>       
217
        <group>Sapphire.Diagram.Appearance</group>       
217
    </action>
218
    </action>
218
    <action>
219
    <action>
220
        <id>Sapphire.Diagram.Zoom.In</id>
221
        <label>zoom In</label>
222
        <image>org/eclipse/sapphire/ui/actions/ZoomIn.gif</image>
223
        <description>Zoom in the diagram.</description>
224
        <location>after:Sapphire.Diagram.Layout</location>
225
        <group>Sapphire.Diagram.Appearance</group>
226
        <context>Sapphire.Diagram.Editor</context>
227
        <context>Sapphire.Diagram.Header</context>
228
    </action>
229
    <action>
230
        <id>Sapphire.Diagram.Zoom.Out</id>
231
        <label>zoom out</label>
232
        <image>org/eclipse/sapphire/ui/actions/ZoomOut.gif</image>
233
        <description>Zoom out the diagram.</description>
234
        <location>after:Sapphire.Diagram.Zoom.In</location>
235
        <group>Sapphire.Diagram.Appearance</group>
236
        <context>Sapphire.Diagram.Editor</context>
237
        <context>Sapphire.Diagram.Header</context>
238
    </action>
239
    <action>
240
        <id>Sapphire.Diagram.Zoom.Actual</id>
241
        <label>zoom actual</label>
242
        <image>org/eclipse/sapphire/ui/actions/ZoomActual.gif</image>
243
        <description>Zoom the diagram to actual size.</description>
244
        <location>after:Sapphire.Diagram.Zoom.Out</location>
245
        <group>Sapphire.Diagram.Appearance</group>
246
        <context>Sapphire.Diagram.Editor</context>
247
        <context>Sapphire.Diagram.Header</context>
248
    </action>
249
    <action>
219
        <id>Sapphire.Diagram.Node.Default</id>
250
        <id>Sapphire.Diagram.Node.Default</id>
220
        <context>Sapphire.Diagram.Node</context>
251
        <context>Sapphire.Diagram.Node</context>
221
        <label>default action</label>
252
        <label>default action</label>
Lines 247-252 Link Here
247
        <location>after:Sapphire.Diagram.SelectAll</location>
278
        <location>after:Sapphire.Diagram.SelectAll</location>
248
        <group>Sapphire.Diagram.SelectAll</group>
279
        <group>Sapphire.Diagram.SelectAll</group>
249
    </action>
280
    </action>
281
    <action>
282
        <id>Sapphire.Diagram.Save.As.Image</id>
283
        <label>save as image</label>
284
        <image>org/eclipse/sapphire/ui/actions/SaveAsImage.gif</image>
285
        <description>Save the diagram as an image.</description>
286
        <context>Sapphire.Diagram.Editor</context>
287
        <context>Sapphire.Diagram.Header</context>
288
    </action>
289
    <action>
290
        <id>Sapphire.Diagram.Print</id>
291
        <label>Print</label>
292
        <image>org/eclipse/sapphire/ui/actions/Print.gif</image>
293
        <description>Print the diagram.</description>
294
        <location>after:Sapphire.Diagram.Save.As.Image</location>
295
        <context>Sapphire.Diagram.Editor</context>
296
        <context>Sapphire.Diagram.Header</context>
297
    </action>
250
   
298
   
251
    <action-handler>
299
    <action-handler>
252
        <action>Sapphire.Browse</action>
300
        <action>Sapphire.Browse</action>
(-)src/org/eclipse/sapphire/ui/def/ActionContextRef.java (+2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 *    Gregory Amerson - [346172] [diagram] Add print, zoom, save as image actions
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.sapphire.ui.def;
13
package org.eclipse.sapphire.ui.def;
Lines 55-60 Link Here
55
            SapphireActionSystem.CONTEXT_SECTION,
56
            SapphireActionSystem.CONTEXT_SECTION,
56
            SapphireActionSystem.CONTEXT_VALUE_PROPERTY_EDITOR,
57
            SapphireActionSystem.CONTEXT_VALUE_PROPERTY_EDITOR,
57
            SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR,
58
            SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR,
59
            SapphireActionSystem.CONTEXT_DIAGRAM_HEADER,
58
            SapphireActionSystem.CONTEXT_DIAGRAM,
60
            SapphireActionSystem.CONTEXT_DIAGRAM,
59
            SapphireActionSystem.CONTEXT_DIAGRAM_NODE,
61
            SapphireActionSystem.CONTEXT_DIAGRAM_NODE,
60
            SapphireActionSystem.CONTEXT_DIAGRAM_NODE_HIDDEN,
62
            SapphireActionSystem.CONTEXT_DIAGRAM_NODE_HIDDEN,
(-)META-INF/sapphire-extension.xml (+43 lines)
Lines 10-15 Link Here
10
 *
10
 *
11
 * Contributors:
11
 * Contributors:
12
 *    Ling Hao - initial implementation and ongoing maintenance 
12
 *    Ling Hao - initial implementation and ongoing maintenance 
13
 *    Gregory Amerson - [346172] [diagram] Add print, zoom, save as image actions
13
 ******************************************************************************
14
 ******************************************************************************
14
-->
15
-->
15
16
Lines 40-43 Link Here
40
        <context>Sapphire.Diagram.Node.Hidden</context>
41
        <context>Sapphire.Diagram.Node.Hidden</context>
41
        <context>Sapphire.Diagram.Connection.Hidden</context>
42
        <context>Sapphire.Diagram.Connection.Hidden</context>
42
    </action-handler>
43
    </action-handler>
44
    <action-handler>
45
        <action>Sapphire.Diagram.Print</action>
46
        <context>Sapphire.Diagram.Editor</context>
47
        <context>Sapphire.Diagram.Header</context>
48
        <impl>org.eclipse.sapphire.ui.swt.gef.actions.PrintDiagramActionHandler</impl>
49
    </action-handler>
50
    <action-handler>
51
        <action>Sapphire.Diagram.Save.As.Image</action>
52
        <context>Sapphire.Diagram.Editor</context>
53
        <context>Sapphire.Diagram.Header</context>
54
        <impl>org.eclipse.sapphire.ui.swt.gef.actions.SaveAsImageDiagramActionHandler</impl>
55
    </action-handler>
56
    <action-handler>
57
        <action>Sapphire.Diagram.Zoom.In</action>
58
        <context>Sapphire.Diagram.Editor</context>
59
        <context>Sapphire.Diagram.Header</context>
60
        <impl>org.eclipse.sapphire.ui.swt.gef.actions.ZoomDiagramActionHandler</impl>
61
        <param>
62
            <name>zoom</name>
63
            <value>in</value>
64
        </param>
65
    </action-handler>
66
    <action-handler>
67
        <action>Sapphire.Diagram.Zoom.Out</action>
68
        <context>Sapphire.Diagram.Editor</context>
69
        <context>Sapphire.Diagram.Header</context>
70
        <impl>org.eclipse.sapphire.ui.swt.gef.actions.ZoomDiagramActionHandler</impl>
71
        <param>
72
            <name>zoom</name>
73
            <value>out</value>
74
        </param>
75
    </action-handler>
76
    <action-handler>
77
        <action>Sapphire.Diagram.Zoom.Actual</action>
78
        <context>Sapphire.Diagram.Editor</context>
79
        <context>Sapphire.Diagram.Header</context>
80
        <impl>org.eclipse.sapphire.ui.swt.gef.actions.ZoomDiagramActionHandler</impl>
81
        <param>
82
            <name>zoom</name>
83
            <value>actual</value>
84
        </param>
85
    </action-handler>
43
</extension>
86
</extension>
(-)src/org/eclipse/sapphire/ui/swt/gef/actions/PrintDiagramActionHandler.java (+46 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2012 Liferay
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Gregory Amerson - initial implementation
10
 ******************************************************************************/
11
12
package org.eclipse.sapphire.ui.swt.gef.actions;
13
14
import org.eclipse.gef.ui.actions.PrintAction;
15
import org.eclipse.sapphire.ui.SapphireRenderingContext;
16
import org.eclipse.sapphire.ui.diagram.SapphireDiagramActionHandler;
17
import org.eclipse.sapphire.ui.swt.gef.DiagramRenderingContext;
18
import org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor;
19
20
/**
21
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
22
 */
23
public class PrintDiagramActionHandler extends SapphireDiagramActionHandler
24
{
25
26
    @Override
27
    public boolean canExecute( Object obj )
28
    {
29
        return true;
30
    }
31
32
    @Override
33
    protected Object run( SapphireRenderingContext context )
34
    {
35
        DiagramRenderingContext diagramContext = (DiagramRenderingContext) context;
36
        SapphireDiagramEditor diagramEditor = diagramContext.getDiagramEditor();
37
38
        if( diagramEditor != null )
39
        {
40
            new PrintAction( diagramEditor ).run();
41
        }
42
43
        return null;
44
    }
45
46
}
(-)src/org/eclipse/sapphire/ui/swt/gef/actions/SaveAsImageDiagramActionHandler.java (+119 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2012 Liferay
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Gregory Amerson - initial implementation
10
 ******************************************************************************/
11
12
package org.eclipse.sapphire.ui.swt.gef.actions;
13
14
import java.io.FileOutputStream;
15
16
import org.eclipse.draw2d.IFigure;
17
import org.eclipse.draw2d.SWTGraphics;
18
import org.eclipse.draw2d.geometry.Rectangle;
19
import org.eclipse.gef.GraphicalViewer;
20
import org.eclipse.gef.LayerConstants;
21
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
22
import org.eclipse.sapphire.ui.SapphireRenderingContext;
23
import org.eclipse.sapphire.ui.diagram.SapphireDiagramActionHandler;
24
import org.eclipse.sapphire.ui.swt.gef.DiagramRenderingContext;
25
import org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.graphics.GC;
28
import org.eclipse.swt.graphics.Image;
29
import org.eclipse.swt.graphics.ImageData;
30
import org.eclipse.swt.graphics.ImageLoader;
31
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.FileDialog;
33
import org.eclipse.ui.IEditorInput;
34
import org.eclipse.ui.IFileEditorInput;
35
36
/**
37
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
38
 */
39
public class SaveAsImageDiagramActionHandler extends SapphireDiagramActionHandler
40
{
41
42
    @Override
43
    public boolean canExecute( Object obj )
44
    {
45
        return true;
46
    }
47
48
    @Override
49
    protected Object run( SapphireRenderingContext context )
50
    {
51
        DiagramRenderingContext diagramContext = (DiagramRenderingContext) context;
52
        SapphireDiagramEditor diagramEditor = diagramContext.getDiagramEditor();
53
54
        if( diagramEditor != null )
55
        {
56
            FileDialog dialog = new FileDialog( context.getShell(), SWT.SAVE );
57
58
            IEditorInput editorInput = diagramEditor.getPart().adapt( IEditorInput.class );
59
60
            if( editorInput instanceof IFileEditorInput )
61
            {
62
                dialog.setFilterPath( ( (IFileEditorInput) editorInput ).getFile().getParent().getRawLocation().toOSString() );
63
            }
64
65
            dialog.setFileName( editorInput.getName().replaceAll( ".xml", ".png" ) );
66
67
            dialog.setFilterExtensions( new String[] { "*.png" } );
68
69
            dialog.setText( "Save as image" );
70
71
            dialog.setOverwrite( true );
72
73
            String filePath = dialog.open();
74
75
            if( filePath == null )
76
            {
77
                return null;
78
            }
79
80
            GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter( GraphicalViewer.class );
81
82
            ScalableFreeformRootEditPart rootEditPart =
83
                (ScalableFreeformRootEditPart) graphicalViewer.getRootEditPart();
84
85
            IFigure figure = rootEditPart.getLayer( LayerConstants.PRINTABLE_LAYERS );
86
87
            Rectangle rectangle = figure.getBounds();
88
89
            Image image = new Image( Display.getDefault(), rectangle.width, rectangle.height );
90
91
            GC gc = new GC( image );
92
            SWTGraphics graphics = new SWTGraphics( gc );
93
            figure.paint( graphics );
94
95
            ImageLoader loader = new ImageLoader();
96
            loader.data = new ImageData[] { image.getImageData() };
97
98
            try
99
            {
100
                final FileOutputStream output = new FileOutputStream( filePath );
101
102
                loader.save( output, SWT.IMAGE_PNG );
103
                output.flush();
104
                output.close();
105
106
                image.dispose();
107
                gc.dispose();
108
                graphics.dispose();
109
            }
110
            catch( Exception e )
111
            {
112
            }
113
114
        }
115
116
        return null;
117
    }
118
119
}
(-)src/org/eclipse/sapphire/ui/swt/gef/actions/ZoomDiagramActionHandler.java (+74 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2012 Liferay
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Gregory Amerson - initial implementation
10
 ******************************************************************************/
11
12
package org.eclipse.sapphire.ui.swt.gef.actions;
13
14
import org.eclipse.gef.GraphicalViewer;
15
import org.eclipse.gef.editparts.ZoomManager;
16
import org.eclipse.sapphire.ui.SapphireAction;
17
import org.eclipse.sapphire.ui.SapphireRenderingContext;
18
import org.eclipse.sapphire.ui.def.ActionHandlerDef;
19
import org.eclipse.sapphire.ui.diagram.SapphireDiagramActionHandler;
20
import org.eclipse.sapphire.ui.swt.gef.DiagramRenderingContext;
21
import org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor;
22
23
/**
24
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
25
 */
26
public class ZoomDiagramActionHandler extends SapphireDiagramActionHandler
27
{
28
29
    private String zoom;
30
31
    @Override
32
    public boolean canExecute( Object obj )
33
    {
34
        return true;
35
    }
36
37
    @Override
38
    public void init( SapphireAction action, ActionHandlerDef def )
39
    {
40
        super.init( action, def );
41
42
        this.zoom = def.getParam( "zoom" );
43
    }
44
45
    @Override
46
    protected Object run( SapphireRenderingContext context )
47
    {
48
        DiagramRenderingContext diagramContext = (DiagramRenderingContext) context;
49
        SapphireDiagramEditor diagramEditor = diagramContext.getDiagramEditor();
50
51
        if( diagramEditor != null )
52
        {
53
            GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter( GraphicalViewer.class );
54
55
            ZoomManager zoomManager = (ZoomManager) graphicalViewer.getProperty( ZoomManager.class.toString() );
56
57
            if( "in".equals( this.zoom ) )
58
            {
59
                zoomManager.zoomIn();
60
            }
61
            else if( "out".equals( this.zoom ) )
62
            {
63
                zoomManager.zoomOut();
64
            }
65
            else if( "actual".equals( this.zoom ) )
66
            {
67
                zoomManager.setZoom( 1 );
68
            }
69
        }
70
71
        return null;
72
    }
73
74
}

Return to bug 346172