Java Code Examples for docking.widgets.OptionDialog#showOptionDialog()

The following examples show how to use docking.widgets.OptionDialog#showOptionDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void processItemChanged(ComboBoxItem item) {
	if (item.isUserDefined) {
		if (OptionDialog.showOptionDialog(rootPanel, "Save Changes to Profile?",
			"Profile " + item.file.getName() +
				" has changed.\nDo you want to save your changes?",
			"Yes", OptionDialog.QUESTION_MESSAGE) == OptionDialog.OPTION_ONE) {
			save(item);
		}
	}
	else {
		if (OptionDialog.showOptionDialog(rootPanel, "Save Changes to Another Profile?",
			"You have made changes to the default profile " + item.file.getName() +
				",\nhowever, updating default profiles is not allowed." +
				"\nDo you want to save your changes to another profile?",
			"Yes", OptionDialog.QUESTION_MESSAGE) == OptionDialog.OPTION_ONE) {
			saveAs(item);
		}
	}
}
 
Example 2
Source File: FrontEndPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean closeActiveProject() {
	if (activeProject == null) {
		return true;
	}
	try {
		return fileActionManager.closeProject(true);
	}
	catch (Exception e) {
		Msg.error(this, "Unexpected Exception: " + e.getMessage(), e); // Keep this.
		int result = OptionDialog.showOptionDialog(tool.getToolFrame(), "Close Project Failed",
			"Error Description: [ " + e + " ]" + "\n" +
				"=====> Do you wish to exit Ghidra, possibly losing changes? <=====",
			"Exit Ghidra (Possibly Lose Changes)", OptionDialog.ERROR_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return false;
		}
	}
	return true;
}
 
Example 3
Source File: RegisterValuesPanel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void deleteSelectedRanges() {
	CompoundCmd cmd = new CompoundCmd("Delete Register Value Ranges");
	int[] rows = table.getSelectedRows();
	boolean containsDefaultValues = false;
	for (int row : rows) {
		RegisterValueRange rvr = model.values.get(row);
		if (rvr.isDefault()) {
			containsDefaultValues = true;
		}
		cmd.add(new SetRegisterCmd(selectedRegister, rvr.getStartAddress(), rvr.getEndAddress(),
			null));
	}
	if (containsDefaultValues) {
		int result = OptionDialog.showOptionDialog(table, "Warning",
			"The selected ranges " +
				"contain default values that can't be deleted.\n  Do you want to continue?",
			"Yes", OptionDialog.WARNING_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	if (cmd.size() > 0) {
		tool.execute(cmd, currentProgram);
	}
}
 
Example 4
Source File: ArchiveDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets called when the user clicks on the OK Action for the dialog.
 */
@Override
protected void okCallback() {
	if (checkInput()) {
		// Check if archive file exists.
		String archive = archiveField.getText().trim();
		if (!archive.endsWith(ArchivePlugin.ARCHIVE_EXTENSION)) {
			archive += ArchivePlugin.ARCHIVE_EXTENSION;
		}
		File file = new File(archive);
		if (file.exists() && OptionDialog.showOptionDialog(rootPanel, "Archive File Exists",
			"File " + archive + " exists.\n " + "Do you want to overwrite existing file?",
			"Yes") != OptionDialog.OPTION_ONE) {
			return;
		}

		actionComplete = true;
		close();
	}
	else {
		rootPanel.getToolkit().beep();
	}
}
 
Example 5
Source File: VersionExceptionHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static int showUpgradeDialog(final Component parent, VersionException ve,
		final String filename, final String contentType, final String actionName) {
	final String detailMessage =
		ve.getDetailMessage() == null ? "" : "\n" + ve.getDetailMessage();

	String title = "Upgrade " + contentType + " Data? " + filename;
	String message = "The " + contentType + " file you are attempting to " + actionName +
		" is an older version." + detailMessage + "\n \n" + "Would you like to Upgrade it now?";
	return OptionDialog.showOptionDialog(parent, title, message, "Upgrade",
		OptionDialog.QUESTION_MESSAGE);
}
 
Example 6
Source File: PdbSymbolServerPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean askIncludePeHeaderPdbPath() throws CancelledException {
	//@formatter:off
	int choice = OptionDialog.showOptionDialog(
		null,
		"PE-specified PDB Path",
		"Unsafe: Include PE-specified PDB Path in search for existing PDB",
		"Yes",
		"No");
	//@formatter:on

	if (choice == OptionDialog.CANCEL_OPTION) {
		throw new CancelledException();
	}
	return (choice == OptionDialog.OPTION_ONE);
}
 
Example 7
Source File: PluginTool.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/** 
 * Called when it is time to save the tool.  Handles auto-saving logic.
 * @return true if a save happened
 */
protected boolean doSaveTool() {
	if (toolServices.canAutoSave(this)) {
		saveTool();
	}
	else {
		if (configChangedFlag) {
			int result = OptionDialog.showOptionDialog(getToolFrame(), SAVE_DIALOG_TITLE,
				"This tool has changed.  There are/were multiple instances of this tool\n" +
					"running and Ghidra cannot determine if this tool instance should\n" +
					"automatically be saved.  Do you want to save the configuration of this tool\n" +
					"instance?",
				"Save", "Save As...", "Don't Save", OptionDialog.WARNING_MESSAGE);
			if (result == OptionDialog.CANCEL_OPTION) {
				return false;
			}
			if (result == OptionDialog.OPTION_ONE) {
				saveTool();
			}
			else if (result == OptionDialog.OPTION_TWO) {
				boolean didSave = saveToolAs();
				if (!didSave) {
					return doSaveTool();
				}
			}
			// option 3 is don't save; just exit
		}
	}
	return true;
}
 
Example 8
Source File: ProjectDataDeleteTask.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean confirmDeleteFiles() {

		int fileCount = filesToDelete.size();
		String files = fileCount != 1 ? fileCount + " files" : " 1 file";
		if (!foldersToDelete.isEmpty()) {
			int folderCount = foldersToDelete.size();
			files += folderCount > 1 ? " and " + folderCount + " folders" : " and 1 folder";
		}

		StringBuilder buffy = new StringBuilder("<html>");
		buffy.append("<div style='font-size: 110%; text-align: center;'>");
		buffy.append("<span>");
		buffy.append("Are you sure you want to <u>permanently</u> delete " + files + "?");
		buffy.append("</span><br><br>");

		buffy.append("<span style='color: red;'>");
		buffy.append("There is no undo operation!");
		buffy.append("</span>");
		buffy.append("</div>");

		/*
		msg +=
			"<div style='margin-bottom: 20pt; font-size: 110%; text-align: center; color: red;'>Are you sure you want to permanently delete these files?</div>" +
				"<div style='margin-bottom: 20pt; text-align: center; font-weight: bold;'>There is no undo operation</div>";
				*/

		int choice = OptionDialog.showOptionDialog(parentComponent, "Confirm Delete Files?",
			buffy.toString(), "Delete Files", OptionDialog.QUESTION_MESSAGE, "Cancel");
		return choice == OptionDialog.OPTION_ONE;
	}
 
Example 9
Source File: ProjectDataDeleteTask.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean confirmUserSkipFailedPreprocessedFiles() {

		String msg = "<html><div style='margin-bottom: 20pt; text-align: center;'>There were " +
			failPreprocessCheckedOut.size() +
			" versioned and checked-out files in the requested set of files that cannot be deleted.</div>" +
			"<div style='margin-bottom: 20pt; text-align: center;'>Skip these files and continue or cancel delete operation?</div>";

		if (OptionDialog.showOptionDialog(parentComponent, "Continue and Skip Problem Files?", msg,
			"Skip and Continue") != OptionDialog.OPTION_ONE) {
			return false;
		}

		return true;
	}
 
Example 10
Source File: DataTypeManagerHandler.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean acquireSaveLock(UndoableDomainObject undoableDomainObject) {
	if (!undoableDomainObject.lock(null)) {
		String title = "Save " + CONTENT_NAME + " (Busy)";
		StringBuilder buf = new StringBuilder();
		buf.append("The " + CONTENT_NAME + " is currently being modified by \n");
		buf.append("the following actions:\n ");
		Transaction t = undoableDomainObject.getCurrentTransaction();
		List<String> list = t.getOpenSubTransactions();
		Iterator<String> it = list.iterator();
		while (it.hasNext()) {
			buf.append("\n     ");
			buf.append(it.next());
		}
		buf.append("\n \n");
		buf.append(
			"WARNING! The above task(s) should be cancelled before attempting a Save.\n");
		buf.append("Only proceed if unable to cancel them.\n \n");
		buf.append(
			"If you continue, all changes made by these tasks, as well as any other overlapping task,\n");
		buf.append(
			"will be LOST and subsequent transaction errors may occur while these tasks remain active.\n \n");

		int result = OptionDialog.showOptionDialog(tool.getToolFrame(), title, buf.toString(),
			"Save Archive!", OptionDialog.WARNING_MESSAGE);

		if (result == OptionDialog.OPTION_ONE) {
			undoableDomainObject.forceLock(true, "Save Archive");
			return true;
		}
		return false;
	}
	return true;
}
 
Example 11
Source File: ProjectInfoDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void convertToIndexedFilesystem() {
	if (filesAreOpen()) {
		Msg.showInfo(getClass(), getComponent(),
			"Cannot Convert/Upgrade Project Storage with Open Files",
			"Before your project can be converted, you must close\n" +
				"files in running tools.");
		return;
	}

	RepositoryAdapter rep = project.getRepository();
	if (rep != null) {
		rep.disconnect();
	}

	if (OptionDialog.showOptionDialog(getComponent(), "Confirm Convert/Upgrade Project Storage",
		"Convert/Upgrade Project Storage to latest Indexed Filesystem ?\n \n" +
			"WARNING!  Once converted a project may no longer be opened by\n" +
			"any version of Ghidra older than version 6.1.",
		"Convert", OptionDialog.WARNING_MESSAGE) == OptionDialog.OPTION_ONE) {

		ProjectLocator projectLocator = project.getProjectLocator();
		FileActionManager actionMgr = plugin.getFileActionManager();
		actionMgr.closeProject(false);

		// put the conversion in a task
		ConvertProjectStorageTask task = new ConvertProjectStorageTask(projectLocator);
		new TaskLauncher(task, getComponent(), 500);

		// block until task completes
		if (task.getStatus()) {
			close();
			actionMgr.openProject(projectLocator);
			plugin.getProjectActionManager().showProjectInfo();
		}
	}

}
 
Example 12
Source File: ProjectInfoDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void updateSharedProjectInfo() {
	if (filesAreOpen()) {
		Msg.showInfo(getClass(), getComponent(), "Cannot Change Project Info with Open Files",
			"Before your project info can be updated, you must close\n" +
				"files in running tools and make sure you have no files\n" + "checked out.");
		return;
	}

	SetupProjectPanelManager panelManager =
		new SetupProjectPanelManager(plugin.getTool(), project.getRepository().getServerInfo());
	WizardManager wm = new WizardManager("Change Shared Project Information", true,
		panelManager, CONVERT_ICON);
	wm.showWizard(getComponent());
	RepositoryAdapter rep = panelManager.getProjectRepository();
	if (rep != null) {
		RepositoryAdapter currentRepository = project.getRepository();
		if (currentRepository.getServerInfo().equals(rep.getServerInfo()) &&
			currentRepository.getName().equals(rep.getName())) {
			Msg.showInfo(getClass(), getComponent(), "No Changes Made",
				"No changes were made to the shared project information.");
		}
		else if (OptionDialog.showOptionDialog(getComponent(), "Update Shared Project Info",
			"Are you sure you want to update your shared project information?", "Update",
			OptionDialog.QUESTION_MESSAGE) == OptionDialog.OPTION_ONE) {

			UpdateInfoTask task = new UpdateInfoTask(rep);
			new TaskLauncher(task, getComponent(), 500);
			// block until task completes
			if (task.getStatus()) {
				FileActionManager actionMgr = plugin.getFileActionManager();
				close();
				actionMgr.closeProject(false);
				actionMgr.openProject(project.getProjectLocator());
				plugin.getProjectActionManager().showProjectInfo();
			}
		}
	}

}
 
Example 13
Source File: DefaultProject.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a ProjectLock and attempts to lock it. This handles the case
 * where the project was previously locked.
 * 
 * @param locator the project locator
 * @param allowInteractiveForce if true, when a lock cannot be obtained, the
 *            user will be prompted
 * @return A locked ProjectLock
 * @throws ProjectLockException if lock failed
 */
private ProjectLock getProjectLock(ProjectLocator locator, boolean allowInteractiveForce) {
	ProjectLock lock = new ProjectLock(locator);
	if (lock.lock()) {
		return lock;
	}

	// in headless mode, just spit out an error
	if (!allowInteractiveForce || SystemUtilities.isInHeadlessMode()) {
		return null;
	}

	String projectStr = "Project: " + HTMLUtilities.escapeHTML(locator.getLocation()) +
		System.getProperty("file.separator") + HTMLUtilities.escapeHTML(locator.getName());
	String lockInformation = lock.getExistingLockFileInformation();
	if (!lock.canForceLock()) {
		Msg.showInfo(getClass(), null, "Project Locked",
			"<html>Project is locked. You have another instance of Ghidra<br>" +
				"already running with this project open (locally or remotely).<br><br>" +
				projectStr + "<br><br>" + "Lock information: " + lockInformation);
		return null;
	}

	int userChoice = OptionDialog.showOptionDialog(null, "Project Locked - Delete Lock?",
		"<html>Project is locked. You may have another instance of Ghidra<br>" +
			"already running with this project opened (locally or remotely).<br>" + projectStr +
			"<br><br>" + "If this is not the case, you can delete the lock file:  <br><b>" +
			locator.getProjectLockFile().getAbsolutePath() + "</b>.<br><br>" +
			"Lock information: " + lockInformation,
		"Delete Lock", OptionDialog.QUESTION_MESSAGE);
	if (userChoice == OptionDialog.OPTION_ONE) { // Delete Lock
		if (lock.forceLock()) {
			return lock;
		}

		Msg.showError(this, null, "Error", "Attempt to force lock failed! " + locator);
	}
	return null;
}
 
Example 14
Source File: GoToHelper.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createExternalAssociation(Program program, String extProgName) {
	int result = OptionDialog.showOptionDialog(null, "No Program Association",
		"The external program name \"" + extProgName +
			"\" is not associated with a Ghidra Program\n" +
			"Would you like to create an association?",
		"Create Association", OptionDialog.QUESTION_MESSAGE);
	if (result == OptionDialog.CANCEL_OPTION) {
		return;
	}
	final DataTreeDialog dialog = new DataTreeDialog(null,
		"Choose External Program (" + extProgName + ")", DataTreeDialog.OPEN);

	dialog.setSearchText(extProgName);
	dialog.setHelpLocation(new HelpLocation("ReferencesPlugin", "ChooseExternalProgram"));
	tool.showDialog(dialog);
	DomainFile domainFile = dialog.getDomainFile();
	if (dialog.wasCancelled() || domainFile == null) {
		return;
	}
	String pathName = domainFile.toString();
	ExternalManager externalManager = program.getExternalManager();
	String externalLibraryPath = externalManager.getExternalLibraryPath(extProgName);
	if (!pathName.equals(externalLibraryPath)) {
		Command cmd = new SetExternalNameCmd(extProgName, domainFile.getPathname());
		tool.execute(cmd, program);
	}
}
 
Example 15
Source File: ExporterDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean tryExport(TaskMonitor monitor) {
	Exporter exporter = getSelectedExporter();

	exporter.setExporterServiceProvider(tool);
	DomainObject dobj = getDomainObject(monitor);
	if (dobj == null) {
		return false;
	}
	ProgramSelection selection = getApplicableProgramSeletion();
	File outputFile = getSelectedOutputFile();

	try {
		if (outputFile.exists() &&
			OptionDialog.showOptionDialog(getComponent(), "Overwrite Existing File?",
				"The file " + outputFile + " already exists.\nDo you want to overwrite it?",
				"Overwrite", OptionDialog.QUESTION_MESSAGE) != OptionDialog.OPTION_ONE) {
			return false;
		}
		if (options != null) {
			exporter.setOptions(options);
		}
		boolean success = exporter.export(outputFile, dobj, selection, monitor);
		displaySummaryResults(exporter, dobj);
		return success;
	}
	catch (Exception e) {
		Msg.error(this, "Exception exporting", e);
		SystemUtilities.runSwingLater(() -> setStatusText(
			"Exception exporting: " + e.getMessage() + ".  If null, see log for details."));
	}
	return false;
}
 
Example 16
Source File: DataTypeManagerHandler.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private boolean getSaveAsLock(UndoableDomainObject undoableDomainObject) {
	if (!undoableDomainObject.lock(null)) {
		String title = "Save " + CONTENT_NAME + " As (Busy)";
		StringBuffer buf = new StringBuffer();
		buf.append("The " + CONTENT_NAME +
			" is currently being modified by the following actions/tasks:\n \n");
		Transaction t = undoableDomainObject.getCurrentTransaction();
		List<String> list = t.getOpenSubTransactions();
		Iterator<String> it = list.iterator();
		while (it.hasNext()) {
			buf.append("\n     ");
			buf.append(it.next());
		}
		buf.append("\n \n");
		buf.append(
			"WARNING! The above task(s) should be cancelled before attempting a Save As...\n");
		buf.append("Only proceed if unable to cancel them.\n \n");
		buf.append(
			"If you click 'Save Archive As (Rollback)' {recommended}, all changes made\n");
		buf.append("by these tasks, as well as any other overlapping task, will be LOST!\n");
		buf.append(
			"If you click 'Save As (As Is)', the archive will be saved in its current\n");
		buf.append("state which may contain some incomplete data.\n");
		buf.append("Any forced save may also result in subsequent transaction errors while\n");
		buf.append("the above tasks remain active.\n ");

		int result = OptionDialog.showOptionDialog(tool.getToolFrame(), title, buf.toString(),
			"Save Archive As (Rollback)!", "Save Archive As (As Is)!",
			OptionDialog.WARNING_MESSAGE);

		if (result == OptionDialog.OPTION_ONE) {
			undoableDomainObject.forceLock(true, "Save Archive As");
			return true;
		}
		else if (result == OptionDialog.OPTION_TWO) {
			undoableDomainObject.forceLock(false, "Save Archive As");
			return true;
		}
		return false;
	}
	return true;
}
 
Example 17
Source File: CommitSingleDataTypeAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	GTree gTree = (GTree) context.getContextObject();
	TreePath[] selectionPaths = gTree.getSelectionPaths();
	if (selectionPaths == null || selectionPaths.length != 1) {
		return;
	}
	GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
	if (!(node instanceof DataTypeNode)) {
		return;
	}
	DataTypeNode dataTypeNode = (DataTypeNode) node;
	DataType dataType = dataTypeNode.getDataType();
	DataTypeManager dtm = dataType.getDataTypeManager();
	DataTypeManagerHandler handler = plugin.getDataTypeManagerHandler();
	DataTypeSyncState syncStatus = DataTypeSynchronizer.getSyncStatus(handler, dataType);

	if (syncStatus == DataTypeSyncState.CONFLICT) {
		int result = OptionDialog.showOptionDialog(gTree, "Lose Changes in Archive?",
			"This data type has changes in the archive that will be\n" +
				"overwritten if you commit this data type",
			"Continue?", OptionDialog.WARNING_MESSAGE);
		if (result == OptionDialog.CANCEL_OPTION) {
			return;
		}
	}
	SourceArchive sourceArchive = dataType.getSourceArchive();
	DataTypeManager sourceDTM =
		plugin.getDataTypeManagerHandler().getDataTypeManager(sourceArchive);
	if (sourceDTM == null) {
		Msg.showInfo(getClass(), gTree, "Commit Failed",
			"Source Archive not open: " + sourceArchive.getName());
		return;
	}
	if (!sourceDTM.isUpdatable()) {
		DataTypeUtils.showUnmodifiableArchiveErrorMessage(gTree, "Commit Failed!", sourceDTM);
		return;
	}
	if (!dataType.getDataTypeManager().isUpdatable()) {
		DataTypeUtils.showUnmodifiableArchiveErrorMessage(gTree, "Commit Failed",
			dataType.getDataTypeManager());
		return;
	}
	plugin.commit(dataType);

	// Source archive data type manager was already checked for null above.
	DataTypeSynchronizer synchronizer = new DataTypeSynchronizer(handler, dtm, sourceArchive);
	synchronizer.reSyncOutOfSyncInTimeOnlyDataTypes();
}
 
Example 18
Source File: ReferencesPlugin.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Check a memory address and warn the user if it has an issue.
 * 
 * @param c parent component or null
 * @param mem program memory
 * @param addr address to check
 * @param refOffset offset from addr
 * @return addr to be used or null if user cancels
 */
Address checkMemoryAddress(Component c, Program p, Address addr, long refOffset) {
	String warningMsg = "";
	String refOffStr = "";
	if (refOffset != 0) {
		boolean neg = (refOffset < 0);
		refOffStr = (neg ? "-" : "+") + "0x" + Long.toHexString(neg ? -refOffset : refOffset);
	}
	AddressSpace space = addr.getAddressSpace();
	if (space instanceof OverlayAddressSpace) {
		OverlayAddressSpace overlaySpace = (OverlayAddressSpace) space;
		AddressSpace baseSpace =
			p.getAddressFactory().getAddressSpace(overlaySpace.getBaseSpaceID());
		long offset = baseSpace.truncateOffset(addr.getOffset() + refOffset);
		if (!overlaySpace.contains(offset)) {
			Address newAddr = overlaySpace.translateAddress(addr, true);
			warningMsg += "The overlay address " + addr.toString(true) + refOffStr +
				" is not contained within the overlay space '" + overlaySpace.getName() +
				"'\n" + "and will get mapped into the underlying address space (" +
				newAddr.toString(true) + refOffStr + ").\n \n";
			addr = newAddr;
		}
	}
	Address testAddr = addr;
	String wrapStr = "";
	if (refOffset != 0) {
		try {
			testAddr = addr.addNoWrap(refOffset);
		}
		catch (AddressOverflowException e) {
			warningMsg += "The address " + addr.toString(true) + refOffStr +
				" must be wrapped within the address space.\n \n";
			testAddr = addr.addWrap(refOffset);
			wrapStr = "wrapped ";
		}
	}
	if (!p.getMemory().contains(testAddr)) {
		warningMsg += "The equivalent " + wrapStr + "address " + testAddr.toString(true) +
			" is not contained within the Program's defined memory blocks.\n \n";
	}
	if (warningMsg.length() != 0) {
		if (c == null) {
			c = tool.getToolFrame();
		}
		int rc = OptionDialog.showOptionDialog(c, "Set Memory Reference",
			warningMsg + "Do you wish to continue?", "Continue", OptionDialog.WARNING_MESSAGE);
		if (rc != OptionDialog.OPTION_ONE) {
			return null;
		}
	}
	return addr;
}
 
Example 19
Source File: SaveToolConfigDialog.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Calls a method in ToolManager to save the tool configuration to a
 * different name.
 */
private void save() {

	String newName = nameField.getText().trim();

	if (newName.length() == 0) {
		this.setStatusText("Please enter or select a name.");
		return;
	}

	if (newName.indexOf(" ") >= 0) {
		setStatusText("Name cannot have spaces.");
		nameField.requestFocus();
		return;
	}
	if (!NamingUtilities.isValidName(newName)) {
		setStatusText("Invalid character in name: " + NamingUtilities.findInvalidChar(newName));
		nameField.requestFocus();
		return;
	}

	if (newName.equals(defaultName)) {
		saveToolConfig();
	}
	else if (isOverwriteExistingTool(newName)) {
		if (OptionDialog.showOptionDialog(tool.getToolFrame(), "Overwrite Tool?",
			"Overwrite existing tool, " + newName + "?", "Overwrite",
			OptionDialog.QUESTION_MESSAGE) == OptionDialog.OPTION_ONE) {
			tool.setToolName(newName);
			saveToolConfig();
		}
		else {
			return;
		}
	}
	else {
		tool.setToolName(newName);
		saveToolConfig();
	}
	close();
}
 
Example 20
Source File: ParseDialog.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void saveAs(ComboBoxItem item) {

		InputDialog d = new InputDialog("Enter Profile Name", "Profile Name");
		plugin.getTool().showDialog(d, getComponent());

		String name = d.getValue();
		if (name != null && name.length() > 0) {
			if (!name.endsWith(FILE_EXTENSION)) {
				name = name + FILE_EXTENSION;
			}
			ResourceFile file = new ResourceFile(parentUserFile, name);
			if (file.equals(item.file)) {
				save(item);
				return;
			}

			if (file.exists()) {
				if (OptionDialog.showOptionDialog(rootPanel, "Overwrite Existing File?",
					"The file " + file.getAbsolutePath() +
						" already exists.\nDo you want to overwrite it?",
					"Yes", OptionDialog.QUESTION_MESSAGE) != OptionDialog.OPTION_ONE) {
					return;
				}
				file.delete();
			}
			ComboBoxItem newItem = new ComboBoxItem(file, true);
			if (itemList.contains(newItem)) {
				itemList.remove(newItem);
				comboModel.removeElement(newItem);
			}
			int index = Collections.binarySearch(itemList, newItem, comparator);
			if (index < 0) {
				index = -index - 1;
			}
			itemList.add(index, newItem);
			saveAsInProgress = true;
			writeProfile(newItem.file);
			newItem.isChanged = false;
			item.isChanged = false;
			try {
				comboModel.insertElementAt(newItem, index);
				comboBox.setSelectedIndex(index);
			}
			finally {
				saveAsInProgress = false;
			}
			setActionsEnabled();
		}
	}