Martin Mucha has uploaded a new change for review. Change subject: userportal,webadmin: moved duplicate UICommand creation to Factory ......................................................................
userportal,webadmin: moved duplicate UICommand creation to Factory Change-Id: I0b3b1344b1a3819e58de4db5093106bedf5291e6 Signed-off-by: Martin Mucha <[email protected]> --- A frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/UICommandFactory.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolPermissionsListModel.java 2 files changed, 36 insertions(+), 36 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/33317/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/UICommandFactory.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/UICommandFactory.java new file mode 100644 index 0000000..b1f219e --- /dev/null +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/UICommandFactory.java @@ -0,0 +1,27 @@ +package org.ovirt.engine.ui.uicommonweb; + +import org.ovirt.engine.ui.uicompat.ConstantsManager; + +public class UICommandFactory { + + private final ICommandTarget target; + + public UICommandFactory(ICommandTarget target) { + this.target = target; + } + + //TODO MM: replace gazillion of code duplicates. + public UICommand createDefaultOkUiCommand(String name) { + UICommand command = new UICommand(name, target); + command.setTitle(ConstantsManager.getInstance().getConstants().ok()); + command.setIsDefault(true); + return command; + } + + public UICommand createCancelUiCommand(String name) { + UICommand command = new UICommand(name, target); //$NON-NLS-1$ + command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); + command.setIsCancel(true); + return command; + } +} diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolPermissionsListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolPermissionsListModel.java index 79f0697..2c883f5 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolPermissionsListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolPermissionsListModel.java @@ -15,6 +15,7 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.uicommonweb.UICommand; +import org.ovirt.engine.ui.uicommonweb.UICommandFactory; import org.ovirt.engine.ui.uicommonweb.help.HelpTag; import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel; import org.ovirt.engine.ui.uicommonweb.models.EntityModel; @@ -42,10 +43,13 @@ this.addPermissionCommand = new UICommand("AddPermission", this); //$NON-NLS-1$ this.removePermissionCommand = new UICommand("RemovePermission", this); //$NON-NLS-1$ - removeConfirmedUiCommand = createRemoveConfirmedUiCommand(); - removeCanceledUiCommand = createRemoveCancelledUiCommand(); - attachPermissionsConfirmedUiCommand = createAttachPermissionsConfirmedUiCommand(); - attachPermissionsCancelledUiCommand = createAttachPermissionCancelledUiCommand(); + final UICommandFactory uiCommandFactory = new UICommandFactory(this); + + //TODO MM: is this 'name' parameter of UICommand good for anything? + removeConfirmedUiCommand = uiCommandFactory.createDefaultOkUiCommand("RemovePermission"); //$NON-NLS-1$ + removeCanceledUiCommand = uiCommandFactory.createCancelUiCommand("CancelPermissionRemoval"); //$NON-NLS-1$ + attachPermissionsConfirmedUiCommand = uiCommandFactory.createDefaultOkUiCommand("AttachPermissions"); //$NON-NLS-1$ + attachPermissionsCancelledUiCommand = uiCommandFactory.createCancelUiCommand("CancelPermissionAttach"); //$NON-NLS-1$ updateActionAvailability(); } @@ -100,6 +104,7 @@ //TODO MM: duplicates? This vs SystemPermissionListModel vs PermissionListModel List<DbUser> dbUsers = new ArrayList<DbUser>(selectedItems.size()); for (Object selectedItem : selectedItems) { + @SuppressWarnings("unchecked") EntityModel<DbUser> selectedItemCasted = (EntityModel<DbUser>) selectedItem; dbUsers.add(selectedItemCasted.getEntity()); } @@ -164,38 +169,6 @@ public void attachPermissionsCancelled() { setWindow(null); - } - - private UICommand createRemoveConfirmedUiCommand() { - return createDefaultOkUiCommand("RemovePermission"); //$NON-NLS-1$ - } - - private UICommand createAttachPermissionsConfirmedUiCommand() { - return createDefaultOkUiCommand("AttachPermissions"); //$NON-NLS-1$ - } - - private UICommand createRemoveCancelledUiCommand() { - return createCancelUiCommand("CancelPermissionRemoval"); //$NON-NLS-1$ - } - - private UICommand createAttachPermissionCancelledUiCommand() { - return createCancelUiCommand("CancelPermissionAttach"); //$NON-NLS-1$ - } - - //TODO MM: is this 'name' parameter of UICommand good for anything? - //TODO MM: move to UICommand class or create UICommandFactory and replace gazillion of code duplicites. - private UICommand createDefaultOkUiCommand(String name) { - UICommand command = new UICommand(name, this); - command.setTitle(ConstantsManager.getInstance().getConstants().ok()); - command.setIsDefault(true); - return command; - } - - private UICommand createCancelUiCommand(String name) { - UICommand command = new UICommand(name, this); //$NON-NLS-1$ - command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); - command.setIsCancel(true); - return command; } //TODO MM: remove duplicity with: org.ovirt.engine.ui.uicommonweb.models.configure.SystemPermissionListModel.add() -- To view, visit http://gerrit.ovirt.org/33317 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0b3b1344b1a3819e58de4db5093106bedf5291e6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Mucha <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
