use of org.archicontribs.modelrepository.grafico.ArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class HistoryView method selectionChanged.
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part == this) {
return;
}
Object selected = ((IStructuredSelection) selection).getFirstElement();
IArchiRepository selectedRepository = null;
// Repository selected
if (selected instanceof IArchiRepository) {
selectedRepository = (IArchiRepository) selected;
} else // Model selected, but is it in a git repo?
{
IArchimateModel model = part.getAdapter(IArchimateModel.class);
if (GraficoUtils.isModelInLocalRepository(model)) {
selectedRepository = new ArchiRepository(GraficoUtils.getLocalRepositoryFolderForModel(model));
}
}
// Update if selectedRepository is different
if (selectedRepository != null && !selectedRepository.equals(fSelectedRepository)) {
// Set label text
// $NON-NLS-1$
fRepoLabel.setText(Messages.HistoryView_0 + " " + selectedRepository.getName());
getViewer().setInput(selectedRepository);
// Do the table kludge
((UpdatingTableColumnLayout) getViewer().getTable().getParent().getLayout()).doRelayout();
// Update actions
fActionExtractCommit.setRepository(selectedRepository);
// fActionRevertSingleCommit.setRepository(selectedRepository);
fActionRevertUptoCommit.setRepository(selectedRepository);
fActionRestoreCommit.setRepository(selectedRepository);
fActionUndoLastCommit.setRepository(selectedRepository);
fActionResetToRemoteCommit.setRepository(selectedRepository);
// Select first row
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!getViewer().getTable().isDisposed()) {
Object element = getViewer().getElementAt(0);
if (element != null) {
getViewer().setSelection(new StructuredSelection(element));
}
}
}
});
// Store last selected
fSelectedRepository = selectedRepository;
}
}
use of org.archicontribs.modelrepository.grafico.ArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class ModelRepositoryPlugin method propertyChange.
@Override
public void propertyChange(PropertyChangeEvent evt) {
// Notify on Save
if (evt.getPropertyName().equals(IEditorModelManager.PROPERTY_MODEL_SAVED)) {
IArchimateModel model = (IArchimateModel) evt.getNewValue();
if (GraficoUtils.isModelInLocalRepository(model)) {
IArchiRepository repo = new ArchiRepository(GraficoUtils.getLocalRepositoryFolderForModel(model));
RepositoryListenerManager.INSTANCE.fireRepositoryChangedEvent(IRepositoryListener.REPOSITORY_CHANGED, repo);
}
}
}
use of org.archicontribs.modelrepository.grafico.ArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class CloneModelAction method run.
@Override
public void run() {
CloneInputDialog dialog = new CloneInputDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final String userName = dialog.getUsername();
final String userPassword = dialog.getPassword();
if (!StringUtils.isSet(repoURL) && !StringUtils.isSet(userName) && !StringUtils.isSet(userPassword)) {
return;
}
File localRepoFolder = new File(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), GraficoUtils.getLocalGitFolderName(repoURL));
// Folder is not empty
if (localRepoFolder.exists() && localRepoFolder.isDirectory() && localRepoFolder.list().length > 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0, // $NON-NLS-1$
Messages.CloneModelAction_2 + " " + localRepoFolder.getAbsolutePath());
return;
}
setRepository(new ArchiRepository(localRepoFolder));
/**
* Wrapper class to handle progress monitor
*/
class CloneProgressHandler extends ProgressHandler {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
super.run(monitor);
try {
monitor.beginTask(Messages.CloneModelAction_4, IProgressMonitor.UNKNOWN);
// Proxy check
ProxyAuthenticater.update(repoURL);
// Clone
getRepository().cloneModel(repoURL, userName, userPassword, this);
monitor.subTask(Messages.CloneModelAction_5);
// Load it from the Grafico files if we can
IArchimateModel graficoModel = new GraficoModelLoader(getRepository()).loadModel();
// We couldn't load it from Grafico so create a new blank model
if (graficoModel == null) {
// New one. This will open in the tree
IArchimateModel model = IEditorModelManager.INSTANCE.createNewModel();
model.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(model);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
// And do a first commit
getRepository().commitChanges(Messages.CloneModelAction_6, false);
// Save the checksum
getRepository().saveChecksum();
}
// Store repo credentials if option is set
if (ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS)) {
SimpleCredentialsStorage scs = new SimpleCredentialsStorage(new File(getRepository().getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
scs.store(userName, userPassword);
}
// Notify listeners
notifyChangeListeners(IRepositoryListener.REPOSITORY_ADDED);
} catch (GitAPIException | IOException | NoSuchAlgorithmException ex) {
displayErrorDialog(Messages.CloneModelAction_0, ex);
} finally {
monitor.done();
}
}
}
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
pmDialog.run(false, true, new CloneProgressHandler());
} catch (InvocationTargetException | InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
use of org.archicontribs.modelrepository.grafico.ArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class CreateRepoFromModelAction method run.
@Override
public void run() {
NewModelRepoDialog dialog = new NewModelRepoDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final String userName = dialog.getUsername();
final String userPassword = dialog.getPassword();
if (!StringUtils.isSet(repoURL) && !StringUtils.isSet(userName) && !StringUtils.isSet(userPassword)) {
return;
}
File localRepoFolder = new File(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), GraficoUtils.getLocalGitFolderName(repoURL));
// Folder is not empty
if (localRepoFolder.exists() && localRepoFolder.isDirectory() && localRepoFolder.list().length > 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CreateRepoFromModelAction_1, Messages.CreateRepoFromModelAction_2 + " " + // $NON-NLS-1$
localRepoFolder.getAbsolutePath());
return;
}
setRepository(new ArchiRepository(localRepoFolder));
/**
* Wrapper class to handle progress monitor
*/
class CreateRepoProgressHandler extends ProgressHandler {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
super.run(monitor);
try {
monitor.beginTask(Messages.CreateRepoFromModelAction_3, IProgressMonitor.UNKNOWN);
// Proxy check
ProxyAuthenticater.update(repoURL);
// Create a new repo
try (Git git = getRepository().createNewLocalGitRepository(repoURL)) {
}
// TODO: If the model has not been saved yet this is fine but if the model already exists
// We should tell the user this is the case
// Set new file location
fModel.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(fModel);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
monitor.subTask(Messages.CreateRepoFromModelAction_4);
// Commit changes
getRepository().commitChanges(Messages.CreateRepoFromModelAction_5, false);
monitor.subTask(Messages.CreateRepoFromModelAction_6);
// Push
getRepository().pushToRemote(userName, userPassword, null);
// Store repo credentials if option is set
if (ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS)) {
SimpleCredentialsStorage sc = new SimpleCredentialsStorage(new File(getRepository().getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
sc.store(userName, userPassword);
}
// Save the checksum
getRepository().saveChecksum();
} catch (GitAPIException | IOException | NoSuchAlgorithmException | URISyntaxException ex) {
displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
} finally {
monitor.done();
}
}
}
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
pmDialog.run(false, true, new CreateRepoProgressHandler());
} catch (InvocationTargetException | InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
Aggregations