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 (-1 / +70 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] Support zoom, print, and save as image actions in the diagram editor
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.Zoom</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.Zoom</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.Zoom</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
        <location>after:Sapphire.Diagram.SelectAllNodes</location>
287
        <group>Sapphire.Diagram.Export</group>
288
        <context>Sapphire.Diagram.Editor</context>
289
        <context>Sapphire.Diagram.Header</context>
290
    </action>
291
    <action>
292
        <id>Sapphire.Diagram.Print</id>
293
        <label>Print</label>
294
        <image>org/eclipse/sapphire/ui/actions/Print.gif</image>
295
        <description>Print the diagram.</description>
296
        <location>after:Sapphire.Diagram.Save.As.Image</location>
297
        <group>Sapphire.Diagram.Export</group>
298
        <context>Sapphire.Diagram.Editor</context>
299
        <context>Sapphire.Diagram.Header</context>
300
    </action>
250
   
301
   
251
    <action-handler>
302
    <action-handler>
252
        <action>Sapphire.Browse</action>
303
        <action>Sapphire.Browse</action>
Lines 396-402 Link Here
396
        <action>Sapphire.Diagram.SelectAllNodes</action>
447
        <action>Sapphire.Diagram.SelectAllNodes</action>
397
        <impl>org.eclipse.sapphire.ui.diagram.actions.DiagramSelectAllNodesActionHandler</impl>
448
        <impl>org.eclipse.sapphire.ui.diagram.actions.DiagramSelectAllNodesActionHandler</impl>
398
        <context>Sapphire.Diagram.Editor</context>
449
        <context>Sapphire.Diagram.Editor</context>
399
    </action-handler>    
450
    </action-handler>
451
    <action-handler>
452
        <action>Sapphire.Diagram.Zoom.In</action>
453
        <context>Sapphire.Diagram.Editor</context>
454
        <context>Sapphire.Diagram.Header</context>
455
        <impl>org.eclipse.sapphire.ui.diagram.actions.ZoomInDiagramActionHandler</impl>
456
    </action-handler>
457
    <action-handler>
458
        <action>Sapphire.Diagram.Zoom.Out</action>
459
        <context>Sapphire.Diagram.Editor</context>
460
        <context>Sapphire.Diagram.Header</context>
461
        <impl>org.eclipse.sapphire.ui.diagram.actions.ZoomOutDiagramActionHandler</impl>
462
    </action-handler>
463
    <action-handler>
464
        <action>Sapphire.Diagram.Zoom.Actual</action>
465
        <context>Sapphire.Diagram.Editor</context>
466
        <context>Sapphire.Diagram.Header</context>
467
        <impl>org.eclipse.sapphire.ui.diagram.actions.ZoomActualDiagramActionHandler</impl>
468
    </action-handler>
400
    <action-handler-factory>
469
    <action-handler-factory>
401
        <action>Sapphire.Add</action>
470
        <action>Sapphire.Add</action>
402
        <impl>org.eclipse.sapphire.ui.form.editors.masterdetails.internal.OutlineNodeAddActionHandlerFactory</impl>
471
        <impl>org.eclipse.sapphire.ui.form.editors.masterdetails.internal.OutlineNodeAddActionHandlerFactory</impl>
(-)src/org/eclipse/sapphire/ui/def/ActionContextRef.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2012 Oracle
2
 * Copyright (c) 2012 Oracle and Liferay
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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] Support zoom, print, and save as image actions in the diagram editor
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,
(-)src/org/eclipse/sapphire/ui/diagram/actions/ZoomActualDiagramActionHandler.java (+76 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.diagram.actions;
13
14
import org.eclipse.sapphire.Event;
15
import org.eclipse.sapphire.Listener;
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.diagram.editor.SapphireDiagramEditorPagePart;
21
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart.ZoomLevelChangedEvent;
22
23
/**
24
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
25
 */
26
public class ZoomActualDiagramActionHandler extends SapphireDiagramActionHandler
27
{
28
29
    @Override
30
    public boolean canExecute( Object obj )
31
    {
32
        return true;
33
    }
34
    
35
    @Override
36
    public void init( SapphireAction action, ActionHandlerDef def )
37
    {
38
        super.init( action, def );
39
        
40
        this.getPart().nearest( SapphireDiagramEditorPagePart.class ).attach
41
        (
42
            new Listener()
43
            {
44
                @Override
45
                public void handle( Event event )
46
                {
47
                    if( event instanceof ZoomLevelChangedEvent )
48
                    {
49
                        broadcast( new EnablementChangedEvent() );
50
                    }
51
                }
52
            }
53
        );
54
    }
55
    
56
    @Override
57
    public boolean isEnabled()
58
    {
59
        int zoomLevel =
60
            ZoomActualDiagramActionHandler.this.getPart().nearest( SapphireDiagramEditorPagePart.class ).getZoomLevel();
61
        
62
        return zoomLevel != 100;
63
    }
64
65
    @Override
66
    protected Object run( SapphireRenderingContext context )
67
    {
68
        final SapphireDiagramEditorPagePart diagramEditorPart =
69
            this.getPart().nearest( SapphireDiagramEditorPagePart.class );
70
71
        diagramEditorPart.setZoomLevel( 100 );
72
73
        return null;
74
    }
75
76
}
(-)src/org/eclipse/sapphire/ui/diagram/actions/ZoomInDiagramActionHandler.java (+41 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.diagram.actions;
13
14
import org.eclipse.sapphire.ui.SapphireRenderingContext;
15
import org.eclipse.sapphire.ui.diagram.SapphireDiagramActionHandler;
16
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart;
17
18
/**
19
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
20
 */
21
public class ZoomInDiagramActionHandler extends SapphireDiagramActionHandler
22
{
23
24
    @Override
25
    public boolean canExecute( Object obj )
26
    {
27
        return true;
28
    }
29
    
30
    @Override
31
    protected Object run( SapphireRenderingContext context )
32
    {
33
        final SapphireDiagramEditorPagePart diagramEditorPart =
34
            this.getPart().nearest( SapphireDiagramEditorPagePart.class );
35
36
        diagramEditorPart.setZoomLevel( diagramEditorPart.getZoomLevel() + 25 );
37
38
        return null;
39
    }
40
41
}
(-)src/org/eclipse/sapphire/ui/diagram/actions/ZoomOutDiagramActionHandler.java (+41 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.diagram.actions;
13
14
import org.eclipse.sapphire.ui.SapphireRenderingContext;
15
import org.eclipse.sapphire.ui.diagram.SapphireDiagramActionHandler;
16
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart;
17
18
/**
19
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
20
 */
21
public class ZoomOutDiagramActionHandler extends SapphireDiagramActionHandler
22
{
23
24
    @Override
25
    public boolean canExecute( Object obj )
26
    {
27
        return true;
28
    }
29
30
    @Override
31
    protected Object run( SapphireRenderingContext context )
32
    {
33
        final SapphireDiagramEditorPagePart diagramEditorPart =
34
            this.getPart().nearest( SapphireDiagramEditorPagePart.class );
35
36
        diagramEditorPart.setZoomLevel( diagramEditorPart.getZoomLevel() - 25 );
37
38
        return null;
39
    }
40
41
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/SapphireDiagramEditorPagePart.java (-2 / +20 lines)
Lines 1-5 Link Here
1
/******************************************************************************
1
/******************************************************************************
2
 * Copyright (c) 2012 Oracle
2
 * Copyright (c) 2012 Oracle and Liferay
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-15 Link Here
9
 *    Shenxue Zhou - initial implementation and ongoing maintenance
9
 *    Shenxue Zhou - initial implementation and ongoing maintenance
10
 *    Konstantin Komissarchik - [342897] Integrate with properties view
10
 *    Konstantin Komissarchik - [342897] Integrate with properties view
11
 *    Ling Hao - [344319] Image specification for diagram parts inconsistent with the rest of sdef
11
 *    Ling Hao - [344319] Image specification for diagram parts inconsistent with the rest of sdef
12
 *    Konstantin Komissarchik - [375770] Support context menu actions when multiple diagram parts are selected 
12
 *    Konstantin Komissarchik - [375770] Support context menu actions when multiple diagram parts are selected
13
 *    Gregory Amerson - [346172] Support zoom, print, and save as image actions in the diagram editor
13
 ******************************************************************************/
14
 ******************************************************************************/
14
15
15
package org.eclipse.sapphire.ui.diagram.editor;
16
package org.eclipse.sapphire.ui.diagram.editor;
Lines 73-78 Link Here
73
    private int verticalGridUnit;
74
    private int verticalGridUnit;
74
	private List<FunctionResult> connectionImageDataFunctionResults;
75
	private List<FunctionResult> connectionImageDataFunctionResults;
75
	private Point mouseLocation;
76
	private Point mouseLocation;
77
    private int zoomLevel = 100; // zoomLevel cooresponds to 100%, 25 would be 25%, 200 would be 200%
76
78
77
    @Override
79
    @Override
78
    protected void init()
80
    protected void init()
Lines 245-250 Link Here
245
    	}
247
    	}
246
    }
248
    }
247
    
249
    
250
    public int getZoomLevel()
251
    {
252
        return this.zoomLevel;
253
    }
254
    
255
    public void setZoomLevel(int level)
256
    {
257
        if( this.zoomLevel != level )
258
        {
259
            this.zoomLevel = level;
260
            broadcast( new ZoomLevelChangedEvent() );
261
        }
262
    }
263
    
248
    public int getGridUnit()
264
    public int getGridUnit()
249
    {
265
    {
250
    	return this.gridUnit;
266
    	return this.gridUnit;
Lines 1031-1034 Link Here
1031
    	}
1047
    	}
1032
    	
1048
    	
1033
    }
1049
    }
1050
    
1051
    public static final class ZoomLevelChangedEvent extends Event {}
1034
}
1052
}
(-)META-INF/sapphire-extension.xml (-1 / +14 lines)
Lines 2-8 Link Here
2
2
3
<!-- 
3
<!-- 
4
 ******************************************************************************
4
 ******************************************************************************
5
 * Copyright (c) 2012 Oracle
5
 * Copyright (c) 2012 Oracle and Liferay
6
 * All rights reserved. This program and the accompanying materials
6
 * All rights reserved. This program and the accompanying materials
7
 * are made available under the terms of the Eclipse Public License v1.0
7
 * are made available under the terms of the Eclipse Public License v1.0
8
 * which accompanies this distribution, and is available at
8
 * which accompanies this distribution, and is available at
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] Support zoom, print, and save as image actions in the diagram editor
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>
43
</extension>
56
</extension>
(-)src/org/eclipse/sapphire/ui/swt/gef/SapphireDiagramEditor.java (-5 / +26 lines)
Lines 11-16 Link Here
11
 *    Shenxue Zhou - [365019] SapphireDiagramEditor does not work on non-workspace files 
11
 *    Shenxue Zhou - [365019] SapphireDiagramEditor does not work on non-workspace files 
12
 *    Gregory Amerson - [374022] SapphireGraphicalEditor init with SapphireEditor
12
 *    Gregory Amerson - [374022] SapphireGraphicalEditor init with SapphireEditor
13
 *    Konstantin Komissarchik - [376245] Revert action in StructuredTextEditor does not revert diagram nodes and connections in SapphireDiagramEditor
13
 *    Konstantin Komissarchik - [376245] Revert action in StructuredTextEditor does not revert diagram nodes and connections in SapphireDiagramEditor
14
 *    Gregory Amerson - [346172] Support zoom, print, and save as image actions in the diagram editor
14
 ******************************************************************************/
15
 ******************************************************************************/
15
16
16
package org.eclipse.sapphire.ui.swt.gef;
17
package org.eclipse.sapphire.ui.swt.gef;
Lines 78-83 Link Here
78
import org.eclipse.sapphire.ui.diagram.editor.DiagramPageEvent;
79
import org.eclipse.sapphire.ui.diagram.editor.DiagramPageEvent;
79
import org.eclipse.sapphire.ui.diagram.editor.DiagramPartEvent;
80
import org.eclipse.sapphire.ui.diagram.editor.DiagramPartEvent;
80
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart;
81
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart;
82
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart.ZoomLevelChangedEvent;
81
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramPartListener;
83
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramPartListener;
82
import org.eclipse.sapphire.ui.diagram.layout.DiagramLayoutPersistenceService;
84
import org.eclipse.sapphire.ui.diagram.layout.DiagramLayoutPersistenceService;
83
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
85
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
Lines 153-159 Link Here
153
	private SizeCache bodyCache = new SizeCache();
155
	private SizeCache bodyCache = new SizeCache();
154
	private SizeCache headCache = new SizeCache();	
156
	private SizeCache headCache = new SizeCache();	
155
	private FormColors formColors;
157
	private FormColors formColors;
156
	private Listener diagramHeaderImageListener;
158
	private Listener diagramEditorPagePartListener;
157
	
159
	
158
	private SapphireActionHandlerDelegate selectAllAction;
160
	private SapphireActionHandlerDelegate selectAllAction;
159
	private SapphireActionHandlerDelegate deleteAction;
161
	private SapphireActionHandlerDelegate deleteAction;
Lines 339-345 Link Here
339
		
341
		
340
		this.layoutPersistenceService.attach(this.layoutPersistenceServiceListener);
342
		this.layoutPersistenceService.attach(this.layoutPersistenceServiceListener);
341
		
343
		
342
        this.diagramHeaderImageListener = new Listener()
344
        this.diagramEditorPagePartListener = new Listener()
343
        {
345
        {
344
            @Override
346
            @Override
345
            public void handle( final Event event )
347
            public void handle( final Event event )
Lines 348-358 Link Here
348
                {
350
                {
349
                    refreshFormHeaderImage();
351
                    refreshFormHeaderImage();
350
                }
352
                }
353
                else if( event instanceof ZoomLevelChangedEvent )
354
                {
355
                    refreshZoomLevel();
356
                }
351
            }
357
            }
352
        };
358
        };
353
        
359
        
354
        this.diagramPart.attach( this.diagramHeaderImageListener );
360
        this.diagramPart.attach( this.diagramEditorPagePartListener );
355
				
356
    }
361
    }
357
    
362
    
358
    public IDiagramEditorPageDef getDiagramEditorPageDef()
363
    public IDiagramEditorPageDef getDiagramEditorPageDef()
Lines 1022-1028 Link Here
1022
			layoutPersistenceService.dispose();
1027
			layoutPersistenceService.dispose();
1023
		}
1028
		}
1024
		
1029
		
1025
        this.diagramPart.detach( this.diagramHeaderImageListener );        
1030
        this.diagramPart.detach( this.diagramEditorPagePartListener );        
1026
        final Image image = this.header.getImage();        
1031
        final Image image = this.header.getImage();        
1027
        if( image != null )
1032
        if( image != null )
1028
        {
1033
        {
Lines 1114-1119 Link Here
1114
        }
1119
        }
1115
		
1120
		
1116
	}
1121
	}
1122
    
1123
	private void refreshZoomLevel()
1124
	{
1125
	    int zoomLevel = this.diagramPart.getZoomLevel();
1126
        
1127
	    double zoom = (double) zoomLevel / 100;
1128
        
1129
	    getZoomManager().setZoom( zoom );
1130
	}
1131
    
1132
	private ZoomManager getZoomManager()
1133
	{
1134
	    GraphicalViewer graphicalViewer = (GraphicalViewer) getAdapter( GraphicalViewer.class );
1135
1136
        return (ZoomManager) graphicalViewer.getProperty( ZoomManager.class.toString() );
1137
	}
1117
	
1138
	
1118
	private SapphireDiagramOutline getDiagramOutline()
1139
	private SapphireDiagramOutline getDiagramOutline()
1119
	{
1140
	{
(-)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 (+130 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.modeling.util.NLS;
23
import org.eclipse.sapphire.ui.SapphireRenderingContext;
24
import org.eclipse.sapphire.ui.diagram.SapphireDiagramActionHandler;
25
import org.eclipse.sapphire.ui.swt.gef.DiagramRenderingContext;
26
import org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.graphics.GC;
29
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.graphics.ImageData;
31
import org.eclipse.swt.graphics.ImageLoader;
32
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.swt.widgets.FileDialog;
34
import org.eclipse.ui.IEditorInput;
35
import org.eclipse.ui.IFileEditorInput;
36
37
/**
38
 * @author <a href="mailto:gregory.amerson@liferay.com">Gregory Amerson</a>
39
 */
40
public class SaveAsImageDiagramActionHandler extends SapphireDiagramActionHandler
41
{
42
43
    @Override
44
    public boolean canExecute( Object obj )
45
    {
46
        return true;
47
    }
48
49
    @Override
50
    protected Object run( SapphireRenderingContext context )
51
    {
52
        DiagramRenderingContext diagramContext = (DiagramRenderingContext) context;
53
        SapphireDiagramEditor diagramEditor = diagramContext.getDiagramEditor();
54
55
        if( diagramEditor != null )
56
        {
57
            FileDialog dialog = new FileDialog( context.getShell(), SWT.SAVE );
58
59
            IEditorInput editorInput = diagramEditor.getPart().adapt( IEditorInput.class );
60
61
            if( editorInput instanceof IFileEditorInput )
62
            {
63
                dialog.setFilterPath( ( (IFileEditorInput) editorInput ).getFile().getParent().getRawLocation().toOSString() );
64
            }
65
66
            dialog.setFileName( editorInput.getName().replaceAll( ".xml", ".png" ) );
67
68
            dialog.setFilterExtensions( new String[] { "*.png" } );
69
70
            dialog.setText( Resources.saveAsImageMessage );
71
72
            dialog.setOverwrite( true );
73
74
            String filePath = dialog.open();
75
76
            if( filePath == null )
77
            {
78
                return null;
79
            }
80
81
            GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter( GraphicalViewer.class );
82
83
            ScalableFreeformRootEditPart rootEditPart =
84
                (ScalableFreeformRootEditPart) graphicalViewer.getRootEditPart();
85
86
            IFigure figure = rootEditPart.getLayer( LayerConstants.PRINTABLE_LAYERS );
87
88
            Rectangle rectangle = figure.getBounds();
89
90
            Image image = new Image( Display.getDefault(), rectangle.width, rectangle.height );
91
92
            GC gc = new GC( image );
93
            SWTGraphics graphics = new SWTGraphics( gc );
94
            figure.paint( graphics );
95
96
            ImageLoader loader = new ImageLoader();
97
            loader.data = new ImageData[] { image.getImageData() };
98
99
            try
100
            {
101
                final FileOutputStream output = new FileOutputStream( filePath );
102
103
                loader.save( output, SWT.IMAGE_PNG );
104
                output.flush();
105
                output.close();
106
107
                image.dispose();
108
                gc.dispose();
109
                graphics.dispose();
110
            }
111
            catch( Exception e )
112
            {
113
            }
114
115
        }
116
117
        return null;
118
    }
119
120
    private static final class Resources extends NLS
121
    {
122
        public static String saveAsImageMessage;
123
124
        static
125
        {
126
            initializeMessages( SaveAsImageDiagramActionHandler.class.getName(), Resources.class );
127
        }
128
    }
129
130
}
(-)src/org/eclipse/sapphire/ui/swt/gef/actions/SaveAsImageDiagramActionHandler.properties (+1 lines)
Added Link Here
1
saveAsImageMessage = Save as image 

Return to bug 346172