Alissa Bonas has uploaded a new change for review. Change subject: webadmin: reuse command creation in StorageListModel ......................................................................
webadmin: reuse command creation in StorageListModel Reuse UICommand creation (OK, Cancel, etc) in StorageListModel by extracting it to separate methods. Change-Id: Ib3dc143c78ddb7371b7e2ec77f3b6600391b470d Signed-off-by: Alissa Bonas <[email protected]> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageListModel.java 1 file changed, 31 insertions(+), 46 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/15658/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageListModel.java index 5de9590..8433514 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageListModel.java @@ -318,16 +318,10 @@ model.initialize(); - - UICommand command; - command = new UICommand("OnSave", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); + UICommand command = createOKCommand("OnSave"); //$NON-NLS-1$ model.getCommands().add(command); - command = new UICommand("Cancel", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); + command = createCancelCommand("Cancel"); //$NON-NLS-1$ model.getCommands().add(command); } @@ -418,20 +412,17 @@ UICommand command; if (isStorageEditable) { - command = new UICommand("OnSave", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); + command = createOKCommand("OnSave"); //$NON-NLS-1$ model.getCommands().add(command); - command = new UICommand("Cancel", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); + command = createCancelCommand("Cancel"); //$NON-NLS-1$ model.getCommands().add(command); } else { - command = new UICommand("Cancel", this); //$NON-NLS-1$ + // close is created the same as cancel, but with a different title + // thus most of creation code can be reused. + command = createCancelCommand("Cancel"); //$NON-NLS-1$ command.setTitle(ConstantsManager.getInstance().getConstants().close()); - command.setIsCancel(true); model.getCommands().add(command); } } @@ -645,16 +636,11 @@ model.initialize(); - UICommand command; - command = new UICommand("OnImport", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); + command = createOKCommand("OnImport"); //$NON-NLS-1$ model.getCommands().add(command); - command = new UICommand("Cancel", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); + command = createCancelCommand("Cancel"); //$NON-NLS-1$ model.getCommands().add(command); } @@ -805,23 +791,16 @@ || storage.getStorageDomainType() == StorageDomainType.ImportExport); if (hosts.isEmpty()) { - - UICommand tempVar = new UICommand("Cancel", storageListModel); //$NON-NLS-1$ - tempVar.setTitle(ConstantsManager.getInstance().getConstants().close()); + UICommand tempVar = createCancelCommand("Cancel"); //$NON-NLS-1$ tempVar.setIsDefault(true); - tempVar.setIsCancel(true); removeStorageModel.getCommands().add(tempVar); } else { UICommand command; - command = new UICommand("OnRemove", storageListModel); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); + command = createOKCommand("OnRemove"); //$NON-NLS-1$ removeStorageModel.getCommands().add(command); - command = new UICommand("Cancel", storageListModel); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); + command = createCancelCommand("Cancel"); //$NON-NLS-1$ removeStorageModel.getCommands().add(command); } @@ -869,14 +848,10 @@ UICommand command; - command = new UICommand("OnDestroy", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); + command = createOKCommand("OnDestroy"); //$NON-NLS-1$ model.getCommands().add(command); - command = new UICommand("Cancel", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); + command = createCancelCommand("Cancel"); //$NON-NLS-1$ model.getCommands().add(command); } @@ -1037,15 +1012,10 @@ model.setHashName("force_storage_domain_creation"); //$NON-NLS-1$ model.setItems(usedLunsMessages); - UICommand command; - command = new UICommand("OnSaveSanStorage", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); + UICommand command = createOKCommand("OnSaveSanStorage"); //$NON-NLS-1$ model.getCommands().add(command); - command = new UICommand("CancelConfirm", this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); + command = createCancelCommand("CancelConfirm"); //$NON-NLS-1$ model.getCommands().add(command); } @@ -2268,4 +2238,19 @@ } } } + + private UICommand createCancelCommand(String commandName) { + UICommand command; + command = new UICommand(commandName, this); //$NON-NLS-1$ + command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); + command.setIsCancel(true); + return command; + } + + private UICommand createOKCommand(String commandName) { + UICommand command = new UICommand(commandName, this); + command.setTitle(ConstantsManager.getInstance().getConstants().ok()); + command.setIsDefault(true); + return command; + } } -- To view, visit http://gerrit.ovirt.org/15658 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib3dc143c78ddb7371b7e2ec77f3b6600391b470d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alissa Bonas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
