Skip to main content
summaryrefslogtreecommitdiffstats
blob: 174641216d6ff0764c1b8043a8bb3aad79351ae8 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 *  Copyright (c) 2012  Oracle. All rights reserved.
 *  This program and the accompanying materials are made available under the
 *  terms of the Eclipse Public License v1.0, which accompanies this distribution
 *  and is available at http://www.eclipse.org/legal/epl-v10.html
 *  
 *  Contributors: 
 *  	Oracle - initial API and implementation
 *******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.SelectEcliplseLinkMappingFileDialog;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
import org.eclipse.jpt.jpa.ui.internal.jface.XmlMappingFileViewerFilter;
import org.eclipse.jpt.jpa.ui.internal.wizards.SelectJpaOrmMappingFileDialog;
import org.eclipse.jpt.jpa.ui.internal.wizards.entity.EntityWizardMsg;
import org.eclipse.jpt.jpa.ui.internal.wizards.gen.DefaultTableGenerationWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;

public class DynamicDefaultTableGenerationWizardPage extends
		DefaultTableGenerationWizardPage {

	private Label xmlMappingFileLabel;
	private Text xmlMappingFileText;
	private Button xmlMappingFileBrowseButton;

	public DynamicDefaultTableGenerationWizardPage(JpaProject jpaProject) {
		super(jpaProject);
	}
	
	@Override
	public void createControl(Composite parent) {
		initializeDialogUnits(parent);
		Composite composite = new Composite(parent, SWT.NULL);
		int nColumns= 4		;
		GridLayout layout = new GridLayout();
		layout.numColumns = nColumns;
		composite.setLayout(layout);
		this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_CUSTOMIZE_DEFAULT_ENTITY_GENERATION);

		createXmlMappingFileGroup(composite);
		createDomainJavaClassesPropertiesGroup(composite, 4);
		defaultTableGenPanel = new DynamicTableGenPanel(composite, 4, true, this);

		setControl(composite);
		
		this.setPageComplete( true );
	}

	@Override
	protected void createDomainJavaClassesPropertiesGroup(Composite composite, int columns) {
		Group parent = new Group( composite, SWT.NONE);
		parent.setText( JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_defaultTablePage_domainJavaClass);
		parent.setLayout(new GridLayout( columns, false));
		GridData layoutData = new GridData();
		layoutData.horizontalSpan = columns;
		layoutData.verticalAlignment = SWT.FILL;
		layoutData.horizontalAlignment = SWT.FILL;
		layoutData.grabExcessHorizontalSpace = true;
		layoutData.grabExcessVerticalSpace = false;
		parent.setLayoutData(layoutData);

		createPackageControls(parent, columns);
	}
	
	private void createXmlMappingFileGroup(Composite parent) {
		Composite composite = new Composite(parent, SWT.NULL);
		composite.setLayout(new GridLayout(3, false));
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	

		this.xmlMappingFileLabel = new Label(composite, SWT.LEFT);
		this.xmlMappingFileLabel.setText(JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_defaultTablePage_xmlMappingFile);
		this.xmlMappingFileLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

		this.xmlMappingFileText = new Text(composite, SWT.SINGLE | SWT.BORDER);
		this.xmlMappingFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		this.xmlMappingFileText.addModifyListener(new ModifyListener() {
			
			public void modifyText(ModifyEvent e) {
				handleXmlMappingFileTextModified();
			}
		});
		
		this.xmlMappingFileBrowseButton = new Button(composite, SWT.PUSH);
		this.xmlMappingFileBrowseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL);
		GridData browseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		browseButtonData.horizontalSpan = 1;
		this.xmlMappingFileBrowseButton.setLayoutData(browseButtonData);		
		this.xmlMappingFileBrowseButton.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				handleXmlMappingFileButtonPressed();
			}

			public void widgetDefaultSelected(SelectionEvent e) {
				widgetSelected(e);
			}
		});
	}
	
	private void handleXmlMappingFileTextModified() {
		this.getCustomizer().setXmlMappingFile(this.xmlMappingFileText.getText());
//		validate();
	}

	private void handleXmlMappingFileButtonPressed() {		

		ViewerFilter filter = getDialogViewerFilter(this.jpaProject);
		ITreeContentProvider contentProvider = new WorkbenchContentProvider();
		ILabelProvider labelProvider = new WorkbenchLabelProvider();
		SelectJpaOrmMappingFileDialog dialog = new SelectEcliplseLinkMappingFileDialog(getShell(), this.jpaProject.getProject(), labelProvider, contentProvider);
		dialog.setTitle(JptUiMessages.SelectJpaOrmMappingFileDialog_title);
		dialog.setMessage(JptUiMessages.SelectJpaOrmMappingFileDialog_message);
		dialog.addFilter(filter);
			
		String ormFileName = this.xmlMappingFileText.getText();
		JpaXmlResource resource = jpaProject.getMappingFileXmlResource(new Path(ormFileName));
		IFile initialSelection = (resource != null) ? resource.getFile() : null;
		dialog.setInput(this.jpaProject.getProject());

		if (initialSelection != null) {
			dialog.setInitialSelection(initialSelection);
		}
		if (dialog.open() == Window.OK) {
			String chosenName = dialog.getChosenName();
			this.xmlMappingFileText.setText(chosenName);
			this.getCustomizer().setXmlMappingFile(chosenName);
		}
//		validate();
	}
	
	protected ViewerFilter getDialogViewerFilter(JpaProject jpaProject) {
		return new XmlMappingFileViewerFilter(jpaProject, JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE);
	}
	
	public void setVisible(boolean visible){
		super.setVisible(visible);
		if(visible){
			this.xmlMappingFileText.setText(this.getCustomizer().getXmlMappingFile());
//			validate();
		}
	}
	
//	private void validate() {
//		String errorMessage = null;
//		JpaXmlResource ormXmlResource = getOrmXmlResource();
//		if (ormXmlResource == null) {
//			errorMessage = JptUiMessages.JpaMakePersistentWizardPage_mappingFileDoesNotExistError;
//		}
//		setErrorMessage(errorMessage);
//		setPageComplete(errorMessage == null);
//	}
	
	protected JpaXmlResource getOrmXmlResource() {
		return this.jpaProject.getMappingFileXmlResource(new Path(this.xmlMappingFileText.getText()));
	}
	
}

Back to the top