use of org.omegat.gui.dialogs.NewProjectFileChooser in project omegat by omegat-org.
the class ProjectUICommands method projectCreate.
public static void projectCreate() {
UIThreadsUtil.mustBeSwingThread();
if (Core.getProject().isProjectLoaded()) {
return;
}
// ask for new project dir
NewProjectFileChooser ndc = new NewProjectFileChooser();
int ndcResult = ndc.showSaveDialog(Core.getMainWindow().getApplicationFrame());
if (ndcResult != OmegaTFileChooser.APPROVE_OPTION) {
// user press 'Cancel' in project creation dialog
return;
}
final File dir = ndc.getSelectedFile();
new SwingWorker<Void, Void>() {
protected Void doInBackground() throws Exception {
dir.mkdirs();
// ask about new project properties
ProjectProperties props = new ProjectProperties(dir);
props.setSourceLanguage(Preferences.getPreferenceDefault(Preferences.SOURCE_LOCALE, "EN-US"));
props.setTargetLanguage(Preferences.getPreferenceDefault(Preferences.TARGET_LOCALE, "EN-GB"));
ProjectPropertiesDialog newProjDialog = new ProjectPropertiesDialog(Core.getMainWindow().getApplicationFrame(), props, dir.getAbsolutePath(), ProjectPropertiesDialog.Mode.NEW_PROJECT);
newProjDialog.setVisible(true);
newProjDialog.dispose();
IMainWindow mainWindow = Core.getMainWindow();
Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
Cursor oldCursor = mainWindow.getCursor();
mainWindow.setCursor(hourglassCursor);
final ProjectProperties newProps = newProjDialog.getResult();
if (newProps == null) {
// user clicks on 'Cancel'
dir.delete();
mainWindow.setCursor(oldCursor);
return null;
}
final String projectRoot = newProps.getProjectRoot();
if (!StringUtil.isEmpty(projectRoot)) {
// create project
try {
ProjectFactory.createProject(newProps);
} catch (Exception ex) {
Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
}
}
RecentProjects.add(dir.getAbsolutePath());
mainWindow.setCursor(oldCursor);
return null;
}
}.execute();
}
use of org.omegat.gui.dialogs.NewProjectFileChooser in project omegat by omegat-org.
the class ProjectUICommands method projectOpenMED.
public static void projectOpenMED() {
UIThreadsUtil.mustBeSwingThread();
if (Core.getProject().isProjectLoaded()) {
return;
}
// ask for MED file
ChooseMedProject ndm = new ChooseMedProject();
int ndmResult = ndm.showOpenDialog(Core.getMainWindow().getApplicationFrame());
if (ndmResult != OmegaTFileChooser.APPROVE_OPTION) {
// user press 'Cancel' in project creation dialog
return;
}
final File med = ndm.getSelectedFile();
// ask for new project dir
NewProjectFileChooser ndc = new NewProjectFileChooser();
int ndcResult = ndc.showSaveDialog(Core.getMainWindow().getApplicationFrame());
if (ndcResult != OmegaTFileChooser.APPROVE_OPTION) {
// user press 'Cancel' in project creation dialog
return;
}
final File dir = ndc.getSelectedFile();
new SwingWorker<Void, Void>() {
protected Void doInBackground() throws Exception {
dir.mkdirs();
final ProjectProperties newProps = new ProjectProperties(dir);
ProjectMedProcessing.extractFromMed(med, newProps);
// create project
try {
ProjectFactory.createProject(newProps);
} catch (Exception ex) {
Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
}
RecentProjects.add(dir.getAbsolutePath());
return null;
}
protected void done() {
try {
get();
SwingUtilities.invokeLater(Core.getEditor()::requestFocus);
} catch (Exception ex) {
Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
}
}
}.execute();
}
Aggregations