Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c794479b004af504cc29ad5ca84f56dd50666fec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.wizards;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell;

/**
 * Persists the size of the wizard dialog.
 */
public class ResizableWizard extends Wizard {
	
	private final int DEFAULT_WIDTH;
	private final int DEFAULT_HEIGHT;
    
    private static final String BOUNDS_HEIGHT_KEY = "width"; //$NON-NLS-1$
    private static final String BOUNDS_WIDTH_KEY = "height"; //$NON-NLS-1$
    
    final String fSectionName;
    
    public ResizableWizard(String sectionName, IDialogSettings settings) {
    	this(sectionName, settings, 300, 400);
    }
    
    protected ResizableWizard(String sectionName, IDialogSettings settings, int defaultWidth, int defaultHeight) {
        DEFAULT_WIDTH= defaultWidth;
        DEFAULT_HEIGHT= defaultHeight;
        fSectionName= sectionName;
        setDialogSettings(settings);
    }
    
    protected static int open(Shell shell, ResizableWizard wizard) {
        final WizardDialog dialog= new WizardDialog(shell, wizard);
        dialog.setMinimumPageSize(wizard.loadSize());
        return dialog.open();
    }
    
    public void saveSize() {
        final Rectangle bounds= getContainer().getCurrentPage().getControl().getParent().getClientArea();
    	final IDialogSettings settings= getDialogSettings();
    	if (settings == null)
    		return;
    	
    	IDialogSettings section= settings.getSection(fSectionName); 
    	if (section == null)
    		section= settings.addNewSection(fSectionName);
    	
        section.put(BOUNDS_WIDTH_KEY, bounds.width);
        section.put(BOUNDS_HEIGHT_KEY, bounds.height);
    }
    
    public Point loadSize() {
        final Point size= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        
    	final IDialogSettings settings= getDialogSettings();
    	if (settings == null)
    		return size;
    	
    	final IDialogSettings section= settings.getSection(fSectionName);
    	if (section == null)
    		return size;

        try {
            size.x= section.getInt(BOUNDS_WIDTH_KEY);
            size.y= section.getInt(BOUNDS_HEIGHT_KEY);
        } catch (NumberFormatException e) {
        }
        return size;
    }


    public boolean performFinish() {
        saveSize();
        return true;
    }
}

Back to the top