use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.
the class CUserManager method editUserName.
/**
* Edits a users user name to something else.
*
* @param user The user where the name should be changed.
* @param userName The user name to change the name of the user to.
*
* @return The new user.
* @throws CouldntSaveDataException
*/
public synchronized IUser editUserName(final IUser user, final String userName) throws CouldntSaveDataException {
Preconditions.checkNotNull(user, "IE02723: user argument can not be null");
Preconditions.checkNotNull(userName, "IE02724: userName argument can not be null");
if (!users.contains(user)) {
throw new IllegalStateException("IE02725: User is not known to the user management.");
}
if (containsUserName(userName)) {
throw new IllegalStateException("IE02726: User name is already in use by another user.");
}
final IUser newUser = provider.editUserName(user, userName);
for (final IUserManagerListener listener : listeners) {
try {
listener.editedUser(newUser);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return newUser;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.
the class CResolveAllFunctionDialog method resolveAllFunctions.
/**
* Takes the information from the GUI and forwards functions.
*/
private int resolveAllFunctions() {
int counter = 0;
for (final INaviModule currentModule : m_targetModules) {
for (final INaviFunction currentFunction : currentModule.getContent().getFunctionContainer().getFunctions()) {
final String originalName = currentFunction.getOriginalModulename();
if (!originalName.equalsIgnoreCase(currentModule.getConfiguration().getName()) && !originalName.equalsIgnoreCase("")) {
for (final INaviModule targetModule : m_sourceModules) {
final String targetModuleName = targetModule.getConfiguration().getName();
if (targetModuleName.toUpperCase().contains(originalName.toUpperCase()) && CFunctionHelpers.isForwardableFunction(currentFunction) && (currentFunction.getForwardedFunctionModuleId() == 0)) {
String currentFunctionName = currentFunction.getName();
if (currentFunctionName.startsWith("__imp_")) {
currentFunctionName = currentFunctionName.substring("__imp_".length());
}
try {
final INaviFunction targetFunction = targetModule.getContent().getFunctionContainer().getFunction(currentFunctionName);
currentFunction.setForwardedFunction(targetFunction);
++counter;
} catch (final MaybeNullException exception) {
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
}
}
}
}
return counter;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.
the class CResolveFunctionDialog method resolveFunctions.
/**
* Takes the information from the GUI and forwards functions.
*/
private void resolveFunctions() {
final Object selectedParentString = m_parentBox.getSelectedItem();
if (selectedParentString == null) {
return;
}
final Object selectedModule = m_targetModuleBox.getSelectedItem();
if (selectedModule == null) {
return;
}
final INaviModule targetModule = ((CModuleWrapper) selectedModule).getObject();
if (!targetModule.isLoaded()) {
if (CMessageBox.showYesNoQuestion(this, "The target module must be loaded before functions can be forwarded.\n\n" + "Do you want to load the target module now?") == JOptionPane.NO_OPTION) {
return;
}
CModuleLoader.loadModule(this, targetModule);
}
int counter = 0;
final String parentString = selectedParentString.toString();
for (final INaviFunction sourceFunction : m_module.getContent().getFunctionContainer().getFunctions()) {
if (sourceFunction.getOriginalModulename().equalsIgnoreCase(parentString) && CFunctionHelpers.isForwardableFunction(sourceFunction)) {
String sourceFunctionName = sourceFunction.getName();
if (sourceFunctionName.startsWith("__imp_")) {
sourceFunctionName = sourceFunctionName.substring("__imp_".length());
}
try {
final INaviFunction targetFunction = targetModule.getContent().getFunctionContainer().getFunction(sourceFunctionName);
sourceFunction.setForwardedFunction(targetFunction);
++counter;
} catch (final MaybeNullException exception) {
// There is no function in the target modules with the name of the source function.
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
final String message = "E00023: " + "Could not save function forwarding";
final String description = CUtilityFunctions.createDescription(String.format("Could not forward the function '%s' from module '%s' to module '%s'", sourceFunction.getName(), m_module.getConfiguration().getName(), targetModule.getConfiguration().getName()), new String[] { "The database connection was dropped while saving." }, new String[] { "The changes in function forwarding were not saved. Try saving function " + "forwarding again. If necessary, close the connection to the database and " + "reconnect." });
NaviErrorDialog.show(this, message, description, exception);
}
}
}
if (counter == 0) {
CMessageBox.showInformation(this, "No functions suitable for forwarding were found.");
} else {
CMessageBox.showInformation(this, String.format("%d functions were forwarded from module '%s' to module '%s'", counter, m_module.getConfiguration().getName(), targetModule.getConfiguration().getName()));
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.
the class GenericCommentsTableModel method editComment.
private IComment editComment(IComment comment, String newComment) {
IComment newlySetComment = null;
try {
if (newComment.isEmpty()) {
commentAccessor.deleteComment(comment);
} else {
newlySetComment = commentAccessor.editComment(comment, newComment);
}
} catch (CouldntSaveDataException | CouldntDeleteException e) {
CUtilityFunctions.logException(e);
}
resetCachedComments();
return newlySetComment;
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException in project binnavi by google.
the class GenericCommentsTableModel method keyPressedOrTyped.
@Override
public /**
* Please read the comment in the base class regarding this method - it is somewhat counter-
* intuitive for people used to the Swing keyboard handling model.
*/
void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) {
int commentRow = coordinate.getRow();
IComment comment = null;
if (commentRow < cachedComments.size()) {
comment = cachedComments.get(commentRow);
}
if (!isEditable(coordinate)) {
return;
}
switch(event.getKeyCode()) {
// VK_UNDEFINED implies that this was a KEY_TYPED event.
case KeyEvent.VK_UNDEFINED:
if (commentRow >= cachedComments.size()) {
// Create a new comment.
try {
commentAccessor.appendComment(String.format("%c", event.getKeyChar()));
coordinate.setFieldIndex(1);
} catch (CouldntSaveDataException | CouldntLoadDataException e) {
CUtilityFunctions.logException(e);
}
resetCachedComments();
// the handling code below.
break;
}
switch(event.getKeyChar()) {
case KeyEvent.VK_ENTER:
comment = handleRegularKeyInComment(comment, coordinate, event);
coordinate.setLine(coordinate.getLine() < (comment.getNumberOfCommentLines() - 1) ? coordinate.getLine() + 1 : comment.getNumberOfCommentLines() - 1);
coordinate.setFieldIndex(0);
break;
case KeyEvent.VK_BACK_SPACE:
comment = handleBackspaceKeyInComment(comment, coordinate);
break;
case KeyEvent.VK_DELETE:
comment = handleDeleteKeyInComment(comment, coordinate);
break;
default:
comment = handleRegularKeyInComment(comment, coordinate, event);
coordinate.setFieldIndex(coordinate.getFieldIndex() + 1);
break;
}
break;
case KeyEvent.VK_HOME:
coordinate.setFieldIndex(0);
break;
case KeyEvent.VK_END:
coordinate.setFieldIndex(columns[coordinate.getColumn()].getWidth());
break;
default:
throw new IllegalArgumentException();
}
}
Aggregations