Revision 5ed160dc
Added by Cherian Mathew almost 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceWizard.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
private String dataSourceName; |
35 | 35 |
|
36 |
private boolean editMode; |
|
36 |
//private boolean editMode; |
|
37 |
|
|
38 |
public enum Mode { |
|
39 |
CREATE, |
|
40 |
EDIT, |
|
41 |
CLONE |
|
42 |
} |
|
43 |
|
|
44 |
// default mode is to create a new datasource |
|
45 |
Mode mode = Mode.CREATE; |
|
37 | 46 |
|
38 | 47 |
/** |
39 | 48 |
* <p>Constructor for CdmDataSourceWizard.</p> |
40 | 49 |
*/ |
41 | 50 |
public CdmDataSourceWizard() { |
42 | 51 |
super(); |
43 |
editMode = false;
|
|
52 |
this.mode = Mode.CREATE;
|
|
44 | 53 |
setForcePreviousAndNextButtons(true); |
45 | 54 |
setWindowTitle("Datasource Dialog"); |
55 |
|
|
46 | 56 |
} |
57 |
|
|
47 | 58 |
|
48 | 59 |
/** |
49 | 60 |
* <p>Constructor for CdmDataSourceWizard.</p> |
50 | 61 |
* |
51 | 62 |
* @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object. |
52 | 63 |
*/ |
53 |
public CdmDataSourceWizard(ICdmDataSource dataSource) { |
|
64 |
public CdmDataSourceWizard(ICdmDataSource dataSource, Mode mode) {
|
|
54 | 65 |
super(); |
55 | 66 |
if(dataSource != null){ |
56 |
editMode = true;
|
|
67 |
this.mode = mode;
|
|
57 | 68 |
this.dataSource = dataSource; |
58 | 69 |
dataSourceName = dataSource.getName(); |
59 | 70 |
} |
60 |
setForcePreviousAndNextButtons(true); |
|
71 |
//setForcePreviousAndNextButtons(true);
|
|
61 | 72 |
setWindowTitle("Datasource Dialog"); |
62 | 73 |
} |
63 | 74 |
|
... | ... | |
68 | 79 |
/** {@inheritDoc} */ |
69 | 80 |
@Override |
70 | 81 |
public void addPages() { |
71 |
|
|
72 |
if(editMode){ |
|
82 |
switch(mode) { |
|
83 |
case EDIT: |
|
84 |
case CLONE: |
|
73 | 85 |
if(dataSource.getDatabaseType() == DatabaseTypeEnum.H2){ |
74 | 86 |
dataSourcePage = new CdmDataSourceH2WizardPage(dataSource); |
75 | 87 |
}else if(dataSource.getDatabaseType() == DatabaseTypeEnum.MySQL){ |
76 |
dataSourcePage = new CdmDataSourceMySQLWizardPage(dataSource); |
|
88 |
dataSourcePage = new CdmDataSourceMySQLWizardPage(dataSource, mode);
|
|
77 | 89 |
}else if(dataSource.getDatabaseType() == DatabaseTypeEnum.SqlServer2005){ |
78 | 90 |
dataSourcePage = new CdmDataSourceSQLServerWizardPage(dataSource); |
91 |
}else if(dataSource.getDatabaseType() == DatabaseTypeEnum.PostgreSQL){ |
|
92 |
dataSourcePage = new CdmDataSourcePostgreSQLServerWizardPage(dataSource); |
|
79 | 93 |
}else{ |
80 | 94 |
throw new RuntimeException("Editing a datasource of type '" + dataSource.getDatabaseType() + "' is not supported yet."); |
81 | 95 |
} |
82 | 96 |
|
83 | 97 |
this.addPage(dataSourcePage); |
84 |
}else{
|
|
98 |
case CREATE:
|
|
85 | 99 |
dataSourceSelectionPage = new CdmDataSourceTypeSelectionWizardPage(dataSource); |
86 | 100 |
this.addPage(dataSourceSelectionPage); |
101 |
default: |
|
102 |
|
|
87 | 103 |
} |
104 |
|
|
88 | 105 |
} |
89 | 106 |
|
90 | 107 |
/* (non-Javadoc) |
... | ... | |
93 | 110 |
/** {@inheritDoc} */ |
94 | 111 |
@Override |
95 | 112 |
public boolean performFinish() { |
96 |
|
|
97 |
if(editMode){ |
|
98 |
ICdmDataSource dataSource = dataSourcePage.getDataSource(); |
|
99 |
CdmDataSourceRepository.update(dataSourceName, dataSource); |
|
100 |
|
|
113 |
ICdmDataSource dataSource; |
|
114 |
switch(mode) { |
|
115 |
case EDIT: |
|
116 |
dataSource = dataSourcePage.getUpdatedDataSource(); |
|
117 |
if(dataSourceName.equals(dataSource.getName())) { |
|
118 |
CdmDataSourceRepository.update(dataSourceName, dataSource); |
|
119 |
} else { |
|
120 |
CdmDataSourceRepository.replace(dataSourceName, dataSource); |
|
121 |
} |
|
122 |
return true; |
|
123 |
case CLONE: |
|
124 |
dataSource = dataSourcePage.getUpdatedDataSource(); |
|
125 |
CdmDataSourceRepository.save(dataSourcePage.getDataSourceName(), dataSource); |
|
101 | 126 |
return true; |
102 |
}else{
|
|
127 |
case CREATE:
|
|
103 | 128 |
if(dataSourceSelectionPage.getCredentialsWizardPage() != null){ |
104 |
CdmDataSourceCredentialsWizardPage credentialsWizardPage = dataSourceSelectionPage.getCredentialsWizardPage(); |
|
105 |
CdmDataSourceRepository.save(dataSourceSelectionPage.getDataSourceName(), credentialsWizardPage.getDataSource()); |
|
129 |
CdmDataSourceCredentialsWizardPage credentialsWizardPage = dataSourceSelectionPage.getCredentialsWizardPage();
|
|
130 |
CdmDataSourceRepository.save(dataSourceSelectionPage.getDataSourceName(), credentialsWizardPage.getUpdatedDataSource());
|
|
106 | 131 |
return true; |
107 |
}else{
|
|
132 |
} else {
|
|
108 | 133 |
throw new IllegalStateException("Expected a datasource credentials page to exist"); |
109 | 134 |
} |
135 |
default: |
|
136 |
return false; |
|
110 | 137 |
} |
138 |
|
|
111 | 139 |
} |
112 | 140 |
|
113 | 141 |
/* (non-Javadoc) |
... | ... | |
116 | 144 |
/** {@inheritDoc} */ |
117 | 145 |
@Override |
118 | 146 |
public boolean canFinish() { |
119 |
if(editMode){ |
|
147 |
switch(mode) { |
|
148 |
case EDIT: |
|
149 |
case CLONE: |
|
120 | 150 |
return dataSourcePage.isPageComplete(); |
121 |
}else{
|
|
151 |
case CREATE:
|
|
122 | 152 |
boolean result = true; |
123 | 153 |
result &= dataSourceSelectionPage.isPageComplete(); |
124 | 154 |
if(dataSourceSelectionPage.getCredentialsWizardPage() != null){ |
125 | 155 |
result &= dataSourceSelectionPage.getCredentialsWizardPage().isPageComplete(); |
126 | 156 |
} |
127 |
return result; |
|
157 |
return result; |
|
158 |
default: |
|
159 |
return false; |
|
128 | 160 |
} |
161 |
|
|
129 | 162 |
} |
130 | 163 |
} |
Also available in: Unified diff
refactored wizard dialog and pages to allow for easy in place editing and cloning of datasources.
CdmDataSourceRepository : added methods for (I)PersistentRemoteSource