Skip to content

Commit

Permalink
MainEditor refactoring
Browse files Browse the repository at this point in the history
- enhancement save function
- enhancement save dialog
  • Loading branch information
hangum committed Mar 13, 2014
1 parent eebbafc commit 5de25e1
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 88 deletions.
Expand Up @@ -39,9 +39,9 @@ public abstract class EditorExtension extends EditorPart implements IEditorExten
/** browser.browserFunction의 서비스 헨들러 */
protected EditorFunctionService editorService;

// /** session에서 사용자 정보를 가져다 놓습니다.
// * No context available outside of the request service lifecycle.
// */
/** session에서 사용자 정보를 가져다 놓습니다.
* No context available outside of the request service lifecycle.
*/
protected final String strUserEMail = SessionManager.getEMAIL();
protected String strRoleType = "";
protected final int intUserSeq = SessionManager.getSeq();
Expand All @@ -57,8 +57,6 @@ public abstract class EditorExtension extends EditorPart implements IEditorExten
/** 결과 컬럼이 숫자이면 ,를 찍을 것인지 */
protected boolean isResultComma = GetPreferenceGeneral.getISRDBNumberIsComma();

// protected String QUERY_DELIMITER = ";";

/** 현재 에디터에서 처리해야하는 디비 정보. */
protected UserDBDAO userDB;

Expand Down
Expand Up @@ -14,6 +14,10 @@

public class Messages extends NLS {
private static String BUNDLE_NAME = "com.hangum.tadpole.sql.messages"; //$NON-NLS-1$
public static String ResourceSaveDialog_0;
public static String ResourceSaveDialog_1;
public static String ResourceSaveDialog_2;
public static String ResourceSaveDialog_3;
public static String ResourceSaveDialog_5;
public static String TadpoleSystem_UserDBQuery_11;
public static String TadpoleSystem_UserDBQuery_4;
Expand Down
Expand Up @@ -13,6 +13,8 @@

import java.util.Date;

import com.hangum.tadpold.commons.libs.core.define.PublicTadpoleDefine;

/**
* user_db_resource dao
*
Expand All @@ -26,9 +28,9 @@ public class UserDBResourceDAO {
int user_seq;
int db_seq;
int group_seq;
String name;
String shared_type;
String description;
String name = "";
String shared_type = PublicTadpoleDefine.SHARED_TYPE.PUBLIC.toString();
String description = "";

Date create_time;
String delYn;
Expand Down
Expand Up @@ -44,6 +44,9 @@ public class ResourceSaveDialog extends Dialog {
*/
private static final Logger logger = Logger.getLogger(ResourceSaveDialog.class);

/** 화면에 초기 값을 뿌려 주어야 한다면 사용한다 */
private UserDBResourceDAO initDBResource;

private UserDBDAO userDB;
private PublicTadpoleDefine.RESOURCE_TYPE resourceType;

Expand All @@ -61,17 +64,20 @@ public class ResourceSaveDialog extends Dialog {
* @param userDB
* @param resourceType
*/
public ResourceSaveDialog(Shell parentShell, UserDBDAO userDB, PublicTadpoleDefine.RESOURCE_TYPE resourceType) {
public ResourceSaveDialog(Shell parentShell, UserDBResourceDAO initDBResource, UserDBDAO userDB, PublicTadpoleDefine.RESOURCE_TYPE resourceType) {
super(parentShell);

if(initDBResource == null) this.initDBResource = new UserDBResourceDAO();
else this.initDBResource = initDBResource;

this.userDB = userDB;
this.resourceType = resourceType;
}

@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("Resource Save Dialog"); //$NON-NLS-1$
newShell.setText(Messages.ResourceSaveDialog_3);
}

/**
Expand All @@ -89,13 +95,14 @@ protected Control createDialogArea(Composite parent) {
gridLayout.numColumns = 2;

Label lblName = new Label(container, SWT.NONE);
lblName.setText("Name"); //$NON-NLS-1$
lblName.setText(Messages.ResourceSaveDialog_0);

textName = new Text(container, SWT.BORDER);
textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
textName.setText(initDBResource.getName());

Label lblSharedType = new Label(container, SWT.NONE);
lblSharedType.setText("Shared Type"); //$NON-NLS-1$
lblSharedType.setText(Messages.ResourceSaveDialog_1);

comboSharedType = new Combo(container, SWT.READ_ONLY);
comboSharedType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Expand All @@ -106,10 +113,11 @@ protected Control createDialogArea(Composite parent) {

Label lblDescription = new Label(container, SWT.NONE);
lblDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblDescription.setText("Description"); //$NON-NLS-1$
lblDescription.setText(Messages.ResourceSaveDialog_2);

textDescription = new Text(container, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
textDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
textDescription.setText(initDBResource.getDescription());

initUI();

Expand Down
@@ -1,3 +1,5 @@
ResourceSaveDialog_1=Shared Type
ResourceSaveDialog_2=Description
#Generated by ResourceBundle Editor (http://eclipse-rbe.sourceforge.net)
#-------------------------------------------------------------------------------
# Copyright (c) 2013 hangum.
Expand All @@ -21,6 +23,8 @@
# hangum - initial API and implementation
#-------------------------------------------------------------------------------

ResourceSaveDialog_0=Name
ResourceSaveDialog_3=Resource Save Dialog
ResourceSaveDialog_5 = Name not unique.

TadpoleSystemConnector_10 = Was created.
Expand Down
Expand Up @@ -21,6 +21,14 @@
# hangum - initial API and implementation
#-------------------------------------------------------------------------------

ResourceSaveDialog_0 = \uC774\uB984

ResourceSaveDialog_1 = \uACF5\uC720 \uD0C0\uC785

ResourceSaveDialog_2 = \uC124\uBA85

ResourceSaveDialog_3 = \uB370\uC774\uD130 \uC800\uC7A5

ResourceSaveDialog_5 = \uC774\uB984\uC774 \uC911\uBCF5\uB418\uC5C8\uC2B5\uB2C8\uB2E4.

TadpoleSystemConnector_10 = \uC0DD\uC131\uD588\uC2B5\uB2C8\uB2E4.
Expand Down
Expand Up @@ -315,7 +315,7 @@ public void doSave(IProgressMonitor monitor) {
if(userDBErd == null) {

// file 이름 dialog
ResourceSaveDialog rsDialog = new ResourceSaveDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), userDB, PublicTadpoleDefine.RESOURCE_TYPE.ERD);
ResourceSaveDialog rsDialog = new ResourceSaveDialog(null, null, userDB, PublicTadpoleDefine.RESOURCE_TYPE.ERD);
if (rsDialog.open() == Window.OK) {

try {
Expand Down
Expand Up @@ -107,8 +107,6 @@ public class MainEditor extends EditorExtension {
private String initDefaultEditorStr = ""; //$NON-NLS-1$
/** resource 정보. */
private UserDBResourceDAO dBResource;
/** first save UserDBResource object */
private UserDBResourceDAO userSetDBResource; //$NON-NLS-1$

/** save mode */
private boolean isDirty = false;
Expand Down Expand Up @@ -958,120 +956,118 @@ public void setFocus() {
setOrionTextFocus();
}

@Override
public void doSave(IProgressMonitor monitor) {
// 신규 저장일때는 리소스타입, 이름, 코멘를 입력받습니다.
if(dBResource == null) {
userSetDBResource = getFileName();
if(userSetDBResource == null) return;
/**
* new file name
* @return
*/
private UserDBResourceDAO getFileName(UserDBResourceDAO initDBResource) {
ResourceSaveDialog rsDialog = new ResourceSaveDialog(null, initDBResource, userDB, PublicTadpoleDefine.RESOURCE_TYPE.SQL);
if(rsDialog.open() == Window.OK) {
return rsDialog.getRetResourceDao();
} else {
return null;
}
}

/**
* 데이터를 저장합니다.
*
* @param strContentData
* @return
*/
public boolean calledDoSave(String strContentData) {
boolean isSaved = false;

// 저장을 호출합니다.
try {
String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
if(performSave(strQuery)) {
browserEvaluate(IEditorFunction.SAVE_DATA);
// 신규 저장일때는 리소스타입, 이름, 코멘를 입력받습니다.
if(dBResource == null) {
UserDBResourceDAO newDBResource = getFileName(null);
if(newDBResource == null) return false;

isSaved = saveResourceData(newDBResource, strContentData);
// 업데이트 일때.
} else {
isSaved = updateResourceDate(strContentData);
}

} catch(SWTException e) {
logger.error(RequestInfoUtils.requestInfo("doSave exception", strUserEMail), e); //$NON-NLS-1$
monitor.setCanceled(true);
} finally {
if(isSaved) {
setDirty(false);
browserEvaluate(IEditorFunction.SAVE_DATA);
}
}

return isSaved;
}

@Override
public void doSave(IProgressMonitor monitor) {
String strEditorAllText = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
calledDoSave(strEditorAllText);
}

@Override
public void doSaveAs() {
boolean isSaved = false;

// 신규 저장일때는 리소스타입, 이름, 코멘를 입력받습니다.
userSetDBResource = getFileName();
if(userSetDBResource == null) return;
UserDBResourceDAO newDBResource = getFileName(dBResource);
if(newDBResource == null) return;

// 저장을 호출합니다.
try {
String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
if(performSave(strQuery)) {
browserEvaluate(IEditorFunction.SAVE_DATA);
}
String strEditorAllText = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
isSaved = saveResourceData(newDBResource, strEditorAllText);
} catch(SWTException e) {
logger.error(RequestInfoUtils.requestInfo("doSave exception", strUserEMail), e); //$NON-NLS-1$
} finally {
if(isSaved) {
setDirty(false);
browserEvaluate(IEditorFunction.SAVE_DATA);
}
}
}

/**
* new file name
* @return
*/
private UserDBResourceDAO getFileName() {
ResourceSaveDialog rsDialog = new ResourceSaveDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), userDB, PublicTadpoleDefine.RESOURCE_TYPE.SQL);
if(rsDialog.open() == Window.OK) {
return rsDialog.getRetResourceDao();
} else {
return null;
}
}

/**
* save
* 데이터를 수정합니다.
*
* @param newContents
* @return
*/
public boolean performSave(String newContents) {
boolean boolReturnVal = false;

// new save
if(dBResource == null) {
// editor가 저장 가능 상태인지 검사합니다.
if(!isDirty()) return false;

if(userSetDBResource == null) {
userSetDBResource = getFileName();
if(userSetDBResource == null) return false;
}

boolReturnVal = saveData(newContents);
private boolean updateResourceDate(String newContents) {
try {
TadpoleSystem_UserDBResource.updateResource(dBResource, newContents);
return true;
} catch (Exception e) {
logger.error("update file", e); //$NON-NLS-1$
Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
ExceptionDetailsErrorDialog.openError(getSite().getShell(), "Error", Messages.MainEditor_19, errStatus); //$NON-NLS-1$

// save as
} if(userSetDBResource != null) {
boolReturnVal = saveData(newContents);
if(boolReturnVal) userSetDBResource = null;

// update
} else {
try {
TadpoleSystem_UserDBResource.updateResource(dBResource, newContents);
boolReturnVal = true;
setDirty(false);
} catch (Exception e) {
logger.error("update file", e); //$NON-NLS-1$
Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
ExceptionDetailsErrorDialog.openError(getSite().getShell(), "Error", Messages.MainEditor_19, errStatus); //$NON-NLS-1$

boolReturnVal = false;
}
return false;
}

return boolReturnVal;
}

/**
* save data
*
* @param newDBResource 저장 하려는 리소스
* @param newContents
* @return
*/
private boolean saveData(String newContents) {
private boolean saveResourceData(UserDBResourceDAO newDBResource, String newContents) {
try {
// db 저장
dBResource = TadpoleSystem_UserDBResource.saveResource(userDB, userSetDBResource, newContents);
dBResource = TadpoleSystem_UserDBResource.saveResource(userDB, newDBResource, newContents);
dBResource.setParent(userDB);

// title 수정
setPartName(userSetDBResource.getName());
setPartName(dBResource.getName());

// tree 갱신
PlatformUI.getPreferenceStore().setValue(PublicTadpoleDefine.SAVE_FILE, ""+dBResource.getDb_seq() + ":" + System.currentTimeMillis()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setDirty(false);

userSetDBResource = null;
} catch (Exception e) {
logger.error("save data", e); //$NON-NLS-1$

Expand Down
Expand Up @@ -42,7 +42,7 @@ protected Object doSave(Object[] arguments) {
boolean result = false;
try {
String newContents = (String) arguments[1];
result = editor.performSave(newContents);
result = editor.calledDoSave(newContents);
} catch(Exception e) {
logger.error("do not save", e);
}
Expand Down
Expand Up @@ -374,7 +374,7 @@ public void doSave(IProgressMonitor monitor) {
if(userDBErd == null) {

// file 이름 dialog
ResourceSaveDialog rsDialog = new ResourceSaveDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), userDB, PublicTadpoleDefine.RESOURCE_TYPE.ERD);
ResourceSaveDialog rsDialog = new ResourceSaveDialog(null, null, userDB, PublicTadpoleDefine.RESOURCE_TYPE.ERD);
if (rsDialog.open() == Window.OK) {

try {
Expand Down

0 comments on commit 5de25e1

Please sign in to comment.