refactoring

* separated disableOkActions created for start edit property change event;
* clarifying comment added;
* enableOkActions method renamed to updateOkActions with appropriate logic moved inside
This commit is contained in:
Nadya Zabrodina
2015-01-14 14:56:04 +03:00
parent 3419a30f68
commit 518722db46
2 changed files with 22 additions and 8 deletions
@@ -88,8 +88,12 @@ public class PushController implements Disposable {
myPushLog.getTree().addPropertyChangeListener(PushLogTreeUtil.EDIT_MODE_PROP, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
// when user starts edit we need to force disable ok actions, because tree.isEditing() still false;
// after editing completed okActions will be enabled automatically by dialog validation
Boolean isEditMode = (Boolean)evt.getNewValue();
myDialog.enableOkActions(!isEditMode && isPushAllowed());
if (isEditMode) {
myDialog.disableOkActions();
}
}
});
startLoadingCommits();
@@ -234,7 +238,7 @@ public class PushController implements Disposable {
@Override
public void onSelectionChanged(boolean isSelected) {
myDialog.enableOkActions(isPushAllowed());
myDialog.updateOkActions();
if (isSelected) {
boolean forceLoad = myExcludedRepositoryRoots.remove(model.getRepository().getRoot().getPath());
if (!model.hasCommitInfo() && (forceLoad || !model.getSupport().shouldRequestIncomingChangesForNotCheckedRepositories())) {
@@ -399,7 +403,7 @@ public class PushController implements Disposable {
if (shouldBeSelected) { // never remove selection; initially all checkboxes are not selected
node.setChecked(true);
}
myDialog.enableOkActions(isPushAllowed());
myDialog.updateOkActions();
}
});
}
@@ -52,7 +52,7 @@ public class VcsPushDialog extends DialogWrapper {
myListPanel = myController.getPushPanelLog();
init();
enableOkActions(myController.isPushAllowed());
updateOkActions();
setOKButtonText("Push");
setOKButtonMnemonic('P');
setTitle("Push Commits");
@@ -78,7 +78,7 @@ public class VcsPushDialog extends DialogWrapper {
@Nullable
@Override
protected ValidationInfo doValidate() {
enableOkActions(myController.isPushAllowed());
updateOkActions();
return null;
}
@@ -101,6 +101,10 @@ public class VcsPushDialog extends DialogWrapper {
return actions.toArray(new Action[actions.size()]);
}
private boolean canPush() {
return myController.isPushAllowed();
}
private boolean canForcePush() {
return myController.isForcePushEnabled() && myController.getProhibitedTarget() == null;
}
@@ -121,11 +125,13 @@ public class VcsPushDialog extends DialogWrapper {
protected String getHelpId() {
return ID;
}
public void enableOkActions(boolean isEnabled) {
myPushAction.setEnabled(isEnabled);
public void updateOkActions() {
boolean canPush = canPush();
myPushAction.setEnabled(canPush);
if (myForcePushAction != null) {
boolean canForcePush = canForcePush();
myForcePushAction.setEnabled(isEnabled && canForcePush);
myForcePushAction.setEnabled(canPush && canForcePush);
String tooltip = null;
if (!canForcePush) {
PushTarget target = myController.getProhibitedTarget();
@@ -137,6 +143,10 @@ public class VcsPushDialog extends DialogWrapper {
}
}
public void disableOkActions() {
myPushAction.setEnabled(false);
}
@Nullable
public VcsPushOptionValue getAdditionalOptionValue(@NotNull PushSupport support) {
VcsPushOptionsPanel panel = myAdditionalPanels.get(support);