Skip to content

Commit

Permalink
TEIIDDES-2416 synced profile selection and new/edit buttons with wizard
Browse files Browse the repository at this point in the history
page
* view procedure name is not nulled out with CP changes
* removed unuzed folder and file text widgets
  • Loading branch information
blafond committed Jan 9, 2015
1 parent ddf1d09 commit 2efb54f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public HeaderPropertiesPanel(Composite parent, Properties profileProperties, int
*/
private void createPanel(Composite parent) {
Composite panel = WidgetFactory.createGroup(parent, StringConstants.EMPTY_STRING, SWT.FILL, 2, 1);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.horizontalSpan = 2;
panel.setLayoutData(gd);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected void createCustomContents( Composite parent ) {
Group group = WidgetFactory.createSimpleGroup(parent,
UTIL.getString("Common.Properties.Label")); //$NON-NLS-1$;

scrolled = new Composite(group, SWT.NONE);
scrolled = new Composite(group, SWT.FILL);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
scrolled.setLayout(gridLayout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,16 @@ protected TeiidXmlFileInfo getXmlFileInfo() {
}

void setXmlFileInfo() {
String oldVPName = null;
if( this.xmlFileInfo != null ) {
oldVPName = this.viewProcedureNameText.getText();
}
for (TeiidXmlFileInfo fileInfo : this.info.getXmlFileInfos()) {
if (fileInfo.doProcess()) {
this.xmlFileInfo = fileInfo;
if( oldVPName != null) {
this.xmlFileInfo.setViewProcedureName(oldVPName);
}
break;
}
}
Expand Down Expand Up @@ -688,14 +695,13 @@ protected void synchronizeUi() {
this.viewModelFileText.setText(StringUtilities.EMPTY_STRING);
}

String viewProcedureName = viewProcedureNameText.getText();
if (this.xmlFileInfo != null) {
if (this.xmlFileInfo.getViewProcedureName() != null) {
this.viewProcedureNameText.setText(this.xmlFileInfo
.getViewProcedureName());
} else {
this.viewProcedureNameText
.setText(StringUtilities.EMPTY_STRING);
this.viewProcedureNameText.setText(this.xmlFileInfo.getViewProcedureName());
}
} else {
this.viewProcedureNameText.setText(viewProcedureName);
}

String viewFileName = EMPTY_STRING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ private static String getString(final String id, String arg) {

private ILabelProvider srcLabelProvider;
private Combo srcCombo;
private Text dataFileFolderText;
private Button editCPButton;
private TableViewer fileViewer;
private DataFolderContentProvider fileContentProvider;
Expand All @@ -142,8 +141,6 @@ private static String getString(final String id, String arg) {

private Map<String, Object> parameterMap;

private Text selectedFileText;

private ProfileManager profileManager = ProfileManager.getInstance();
private Collection<IConnectionProfile> connectionProfiles;

Expand Down Expand Up @@ -303,27 +300,7 @@ private void createFolderContentsListGroup(Composite parent) {
Label locationLabel = new Label(folderContentsGroup, SWT.NONE);
locationLabel.setText(getString("folderLocation")); //$NON-NLS-1$

dataFileFolderText = new Text(folderContentsGroup, SWT.BORDER
| SWT.SINGLE);
dataFileFolderText.setBackground(WidgetUtil
.getReadOnlyBackgroundColor());
dataFileFolderText.setForeground(WidgetUtil.getDarkBlueColor());
dataFileFolderText
.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
((GridData)dataFileFolderText.getLayoutData()).horizontalSpan = 2;
dataFileFolderText.setEditable(false);

createFileTableViewer(folderContentsGroup);

Label selectedFileLabel = new Label(folderContentsGroup, SWT.NONE);
selectedFileLabel.setText(getString("selectedRestFile")); //$NON-NLS-1$

selectedFileText = new Text(folderContentsGroup, SWT.BORDER
| SWT.SINGLE);
selectedFileText.setBackground(WidgetUtil.getReadOnlyBackgroundColor());
selectedFileText.setForeground(WidgetUtil.getDarkBlueColor());
selectedFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
selectedFileText.setEditable(false);

Button showFileContentsButton = new Button(folderContentsGroup, SWT.PUSH);
showFileContentsButton.setText("Show Contents"); //$NON-NLS-1$
Expand Down Expand Up @@ -423,41 +400,51 @@ private void createModelGroup(Composite parent) {
}

void profileComboSelectionChanged() {
boolean changed = false;
if (this.srcCombo.getSelectionIndex() > -1) {
String cpName = this.srcCombo.getItem(this.srcCombo
.getSelectionIndex());
for (IConnectionProfile profile : this.connectionProfiles) {
if (profile.getName().equalsIgnoreCase(cpName)) {
setConnectionProfile(profile);
setDataFolderLocation();

clearFileListViewer();
loadFileListViewer();
changed = setConnectionProfile(profile, false);
if (changed) {
clearFileListViewer();
loadFileListViewer();
}
break;
}
}
} else {
setConnectionProfile(null);
changed = true;
setConnectionProfile(null, false);
}

synchronizeUI();

validatePage();

this.editCPButton.setEnabled(getConnectionProfile() != null);
if (changed) {
synchronizeUI();
validatePage();
this.editCPButton.setEnabled(getConnectionProfile() != null);
}
}

public void setDesignerProperties(Properties properties) {
this.designerProperties = properties;
}

private void setConnectionProfile(IConnectionProfile profile) {
private boolean setConnectionProfile(IConnectionProfile profile, boolean wasEdited) {
IConnectionProfile existingProfile = info.getConnectionProfile();

if (!wasEdited && existingProfile != null && profile != null && existingProfile.getName().equals(profile.getName()))
return false;

if (profile == null || isInvalidXmlFileProfile(profile)) {
this.fileViewer.setInput(null);
clearFileListViewer();
}

this.parameterMap.clear();

this.info.setConnectionProfile(profile);
return true;
}

private IConnectionProfile getConnectionProfile() {
Expand Down Expand Up @@ -516,19 +503,19 @@ private void loadFileListViewer() {
// This will be the case if No XML is defined and URL
// version exists OR if nothing is defined in CP
fileViewer.setInput("no input"); //$NON-NLS-1$

if (isRestConnectionProfile()) {
xmlFile = getXmlFileFromRestUrl(getConnectionProfile());
} else {
xmlFile = getXmlFileFromUrl(urlString);
}
if( this.modelsDefinitionSection.getXmlFileInfo() == null ) {
// if( this.modelsDefinitionSection.getXmlFileInfo() == null ) {
if (xmlFile != null && xmlFile.exists()) {
setXmlFile(xmlFile, true, urlString);
}
} else if (xmlFile != null && xmlFile.exists() ) {
resetXmlFile(xmlFile);
}
// } else if (xmlFile != null && xmlFile.exists() ) {
// resetXmlFile(xmlFile);
// }
} else {
fileViewer.setInput(null);
MessageDialog.openError(this.getShell(),
Expand Down Expand Up @@ -668,13 +655,10 @@ private File getXmlFileFromRestUrl(IConnectionProfile profile) {
fos = new FileOutputStream(xmlFile);
write(fos, is);
} else {
jsonFile = File
.createTempFile(
CoreStringUtil.createFileName(filePath),
DOT_XML_LOWER);
jsonFile = File.createTempFile(CoreStringUtil.createFileName(filePath), DOT_XML_LOWER);
fos = new FileOutputStream(jsonFile);
write(fos, is);
xmlFile = convertJsonToXml(jsonFile, CoreStringUtil.createFileName(filePath));
xmlFile = convertJsonToXml(jsonFile);
}

} catch (MalformedURLException ex) {
Expand Down Expand Up @@ -721,7 +705,7 @@ private File getXmlFileFromRestUrl(IConnectionProfile profile) {
* @throws IOException
* @throws JSONException
*/
private File convertJsonToXml(File jsonFile, String name) throws IOException, Exception {
private File convertJsonToXml(File jsonFile) throws IOException, Exception {

String jsonText = null;
try {
Expand All @@ -731,9 +715,7 @@ private File convertJsonToXml(File jsonFile, String name) throws IOException, Ex
ex.printStackTrace();
}
JSONObject jsonObject = new JSONObject(jsonText);

jsonFile = File.createTempFile(
CoreStringUtil.createFileName(jsonFile.getName()), DOT_XML_LOWER);

String xml = XML.toString(jsonObject, "result"); //$NON-NLS-1$
FileUtils.write(xml.getBytes(), jsonFile);
return jsonFile;
Expand Down Expand Up @@ -846,18 +828,27 @@ private String encodeString(String str) throws UnsupportedEncodingException {

private void setXmlFile(File xmlFile, boolean isUrl, String urlString) {
fileViewer.setInput(xmlFile);
TeiidXmlFileInfo fileInfo = this.info.getXmlFileInfo(xmlFile);
if (fileInfo == null) {
fileInfo = new TeiidXmlFileInfo(xmlFile);
fileInfo.setIsUrl(isUrl);
if (isUrl) {
fileInfo.setParameterMap(this.parameterMap);
fileInfo.setXmlFileUrl(urlString);
Properties props = getConnectionProfile().getBaseProperties();
fileInfo.setResponseType((String)props.get(IWSProfileConstants.RESPONSE_TYPE_PROPERTY_KEY));
}
//this.info.addXmlFileInfo(fileInfo);

TeiidXmlFileInfo oldFileInfo = this.info.getXmlFileInfo(xmlFile);
String oldVPName = null;
if( oldFileInfo != null ) {
oldVPName = oldFileInfo.getViewProcedureName();
this.info.clearXmlFileInfos();
}

TeiidXmlFileInfo fileInfo = new TeiidXmlFileInfo(xmlFile);
if( oldVPName != null ) {
fileInfo.setViewProcedureName(oldVPName);
}

fileInfo.setIsUrl(isUrl);
if (isUrl) {
fileInfo.setParameterMap(this.parameterMap);
fileInfo.setXmlFileUrl(urlString);
Properties props = getConnectionProfile().getBaseProperties();
fileInfo.setResponseType((String)props.get(IWSProfileConstants.RESPONSE_TYPE_PROPERTY_KEY));
}

this.info.addXmlFileInfo(fileInfo);
fileViewer.getTable().select(0);
fileViewer.getTable().getItem(0).setChecked(true);
Expand All @@ -868,10 +859,12 @@ private void setXmlFile(File xmlFile, boolean isUrl, String urlString) {
getString("parsingErrorTitle"), //$NON-NLS-1$
fileParsingStatus.getMessage());
}
modelsDefinitionSection.setXmlFileInfo();
}

private void resetXmlFile(File xmlFile) {
fileViewer.setInput(xmlFile);

TeiidXmlFileInfo fileInfo = this.info.getXmlFileInfo(xmlFile);

fileViewer.getTable().select(0);
Expand Down Expand Up @@ -965,17 +958,20 @@ void createNewConnectionProfile() {

CPListener listener = new CPListener();
ProfileManager.getInstance().addProfileListener(listener);

if (wizardDialog.open() == Window.OK) {

refreshConnectionProfiles();

resetCPComboItems();
setConnectionProfile(listener.getChangedProfile());
setConnectionProfile(listener.getChangedProfile(), true);

selectProfile(listener.getChangedProfile());

ProfileManager.getInstance().removeProfileListener(listener);
profileComboSelectionChanged();
}

ProfileManager.getInstance().removeProfileListener(listener);
}

void selectProfile(IConnectionProfile profile) {
Expand Down Expand Up @@ -1010,7 +1006,7 @@ void editConnectionProfile() {

// Update the Combo Box
if (action.wasFinished()) {
setConnectionProfile(listener.getChangedProfile());
setConnectionProfile(listener.getChangedProfile(), true);
this.refreshConnectionProfiles();
WidgetUtil.setComboItems(this.srcCombo, this.connectionProfiles, this.srcLabelProvider, true);

Expand All @@ -1021,7 +1017,7 @@ void editConnectionProfile() {

modelsDefinitionSection.setXmlFileInfo();

setConnectionProfile(null);
setConnectionProfile(null, false);

selectConnectionProfile(currentProfile.getName());

Expand All @@ -1030,10 +1026,9 @@ void editConnectionProfile() {
//profileComboSelectionChanged();

modelsDefinitionSection.setXmlFileInfo();
} else {
// Remove the listener if the dialog is canceled
ProfileManager.getInstance().removeProfileListener(listener);
}

ProfileManager.getInstance().removeProfileListener(listener);
}
}

Expand All @@ -1052,7 +1047,7 @@ void synchronizeUI() {
break;
}
}
this.selectedFileText.setText(fileName);
// this.selectedFileText.setText(fileName);

synchronizing = false;

Expand Down Expand Up @@ -1339,7 +1334,7 @@ public void setVisible(boolean visible) {
this.info.setViewModelName(null);
this.info.setSourceModelName(null);
} else if (!isValidProfileForPage(currentProfile)) {
setConnectionProfile(null);
setConnectionProfile(null, false);
this.fileViewer.setInput(null);
this.info.setViewModelName(null);
this.info.setSourceModelName(null);
Expand All @@ -1349,8 +1344,6 @@ public void setVisible(boolean visible) {
this.info.setSourceModelName(null);
}

setDataFolderLocation();

refreshConnectionProfiles();

resetCPComboItems();
Expand All @@ -1368,40 +1361,4 @@ public void setVisible(boolean visible) {
}
}

private void setDataFolderLocation() {
IConnectionProfile profile = getConnectionProfile();
if (profile != null) {
Properties props = profile.getBaseProperties();
String home = (String) props
.get(IXmlProfileConstants.TEIID_PARENT_DIRECTORY_KEY);
if (home != null) {
String location = home;
if (location.length() > 60) {
int len = location.length();
location = "..." + location.substring(len - 60, len); //$NON-NLS-1$
}
this.dataFileFolderText.setText(location);
this.dataFileFolderText.setToolTipText(home);
} else {
String URL = (String) props
.get(IXmlProfileConstants.URL_PROP_ID);
if (URL != null) {
String location = URL;
if (location.length() > 60) {
int len = location.length();
location = "..." + location.substring(len - 60, len); //$NON-NLS-1$
}
this.dataFileFolderText.setText(location);
this.dataFileFolderText.setToolTipText(URL);
} else {
this.dataFileFolderText.setText(EMPTY_STRING);
this.dataFileFolderText.setToolTipText(EMPTY_STRING);
}
}
} else {
this.dataFileFolderText.setText(EMPTY_STRING);
this.dataFileFolderText.setToolTipText(EMPTY_STRING);
}
}

}

0 comments on commit 2efb54f

Please sign in to comment.