use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.
the class ProjectUICommands method projectTeamCreate.
public static void projectTeamCreate() {
UIThreadsUtil.mustBeSwingThread();
if (Core.getProject().isProjectLoaded()) {
return;
}
new SwingWorker<Void, Void>() {
File projectRoot;
protected Void doInBackground() throws Exception {
Core.getMainWindow().showStatusMessageRB(null);
final NewTeamProject dialog = new NewTeamProject(Core.getMainWindow().getApplicationFrame());
dialog.setVisible(true);
if (!dialog.ok) {
Core.getMainWindow().showStatusMessageRB("TEAM_CANCELLED");
return null;
}
IMainWindow mainWindow = Core.getMainWindow();
Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
Cursor oldCursor = mainWindow.getCursor();
mainWindow.setCursor(hourglassCursor);
Core.getMainWindow().showStatusMessageRB("CT_DOWNLOADING_PROJECT");
// retrieve omegat.project
projectRoot = new File(dialog.getSaveLocation());
List<RepositoryDefinition> repos = new ArrayList<RepositoryDefinition>();
RepositoryDefinition repo = new RepositoryDefinition();
repos.add(repo);
repo.setType(dialog.getRepoType());
repo.setUrl(dialog.getRepoUrl());
RepositoryMapping mapping = new RepositoryMapping();
mapping.setLocal("");
mapping.setRepository("");
repo.getMapping().add(mapping);
RemoteRepositoryProvider remoteRepositoryProvider = new RemoteRepositoryProvider(projectRoot, repos);
remoteRepositoryProvider.switchAllToLatest();
for (String file : new String[] { OConsts.FILE_PROJECT, OConsts.DEFAULT_INTERNAL + '/' + FilterMaster.FILE_FILTERS, OConsts.DEFAULT_INTERNAL + '/' + SRX.CONF_SENTSEG }) {
remoteRepositoryProvider.copyFilesFromRepoToProject(file);
}
ProjectProperties props = ProjectFileStorage.loadProjectProperties(projectRoot);
if (props.getRepositories() == null) {
// We assume it's a 3.6 style project with no repository mapping,
// so we add root repository mapping
props.setRepositories(repos);
}
// We write in all cases, because we might have added default excludes, for instance
ProjectFileStorage.writeProjectFile(props);
// String projectFileURL = dialog.txtRepositoryOrProjectFileURL.getText();
// File localDirectory = new File(dialog.txtDirectory.getText());
// try {
// localDirectory.mkdirs();
// byte[] projectFile = WikiGet.getURLasByteArray(projectFileURL);
// FileUtils.writeByteArrayToFile(new File(localDirectory, OConsts.FILE_PROJECT), projectFile);
// } catch (Exception ex) {
// ex.printStackTrace();
// Core.getMainWindow().displayErrorRB(ex, "TEAM_CHECKOUT_ERROR");
// mainWindow.setCursor(oldCursor);
// return null;
// }
// projectOpen(localDirectory);
mainWindow.setCursor(oldCursor);
return null;
}
@Override
protected void done() {
Core.getMainWindow().showProgressMessage(" ");
try {
get();
if (projectRoot != null) {
// don't ask open if user cancelled previous dialog
SwingUtilities.invokeLater(() -> {
Core.getEditor().requestFocus();
projectOpen(projectRoot);
});
}
} catch (Exception ex) {
Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_DOWNLOAD_TEAM_PROJECT");
Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_DOWNLOAD_TEAM_PROJECT");
}
}
}.execute();
}
use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.
the class ProjectUICommands method projectReload.
public static void projectReload() {
UIThreadsUtil.mustBeSwingThread();
if (!Core.getProject().isProjectLoaded()) {
return;
}
// commit the current entry first
Core.getEditor().commitAndLeave();
final ProjectProperties props = Core.getProject().getProjectProperties();
new SwingWorker<Void, Void>() {
int previousCurEntryNum = Core.getEditor().getCurrentEntryNumber();
protected Void doInBackground() throws Exception {
IMainWindow mainWindow = Core.getMainWindow();
Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
Cursor oldCursor = mainWindow.getCursor();
mainWindow.setCursor(hourglassCursor);
Core.executeExclusively(true, () -> {
Core.getProject().saveProject(true);
ProjectFactory.closeProject();
ProjectFactory.loadProject(props, true);
});
mainWindow.setCursor(oldCursor);
return null;
}
protected void done() {
try {
get();
SwingUtilities.invokeLater(() -> {
// activate entry later - after project will be loaded
Core.getEditor().gotoEntry(previousCurEntryNum);
Core.getEditor().requestFocus();
});
} catch (Exception ex) {
processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
}
}
}.execute();
}
use of org.omegat.core.data.ProjectProperties 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.core.data.ProjectProperties 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