use of org.archicontribs.modelrepository.grafico.IArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class RepoInfoSection method handleSelection.
@Override
protected void handleSelection(IStructuredSelection selection) {
if (selection.getFirstElement() instanceof IArchiRepository) {
IArchiRepository repo = (IArchiRepository) selection.getFirstElement();
fTextFile.setText(repo.getLocalRepositoryFolder().getAbsolutePath());
try {
fTextURL.setText(repo.getOnlineRepositoryURL());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
use of org.archicontribs.modelrepository.grafico.IArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class UserDetailsSection method handleSelection.
@Override
protected void handleSelection(IStructuredSelection selection) {
if (selection.getFirstElement() instanceof IArchiRepository) {
fRepository = (IArchiRepository) selection.getFirstElement();
// $NON-NLS-1$ //$NON-NLS-2$
String globalName = "", globalEmail = "";
// $NON-NLS-1$ //$NON-NLS-2$
String localName = "", localEmail = "";
// Get global name, email
try {
PersonIdent global = GraficoUtils.getGitConfigUserDetails();
globalName = global.getName();
globalEmail = global.getEmailAddress();
} catch (IOException | ConfigInvalidException ex) {
ex.printStackTrace();
}
// Get local name, email
try {
PersonIdent local = fRepository.getUserDetails();
localName = local.getName();
localEmail = local.getEmailAddress();
} catch (IOException ex) {
ex.printStackTrace();
}
fTextName.setText(globalName, localName);
fTextEmail.setText(globalEmail, localEmail);
} else {
// $NON-NLS-1$
System.err.println(getClass() + " failed to get element for " + selection.getFirstElement());
}
}
use of org.archicontribs.modelrepository.grafico.IArchiRepository 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.IArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class ModelRepositoryTreeViewer method startBackgroundJobs.
/**
* Set up and start background jobs
*/
protected void startBackgroundJobs() {
// Refresh file system job
Job refreshFileSystemJob = new // $NON-NLS-1$
Job(// $NON-NLS-1$
"Refresh File System Job") {
// last modified
long lastModified = 0L;
@Override
public IStatus run(IProgressMonitor monitor) {
if (getControl().isDisposed()) {
return Status.OK_STATUS;
}
// If rootFolder has been modifed (child folder added/deleted/renamed) refresh
File rootFolder = getRootFolder();
if (lastModified != 0L && rootFolder.lastModified() != lastModified) {
refreshInBackground();
}
lastModified = rootFolder.lastModified();
if (!getControl().isDisposed()) {
// Schedule again in 5 seconds
schedule(5000);
}
return Status.OK_STATUS;
}
};
refreshFileSystemJob.schedule(5000);
// Fetch Job
Job fetchJob = new // $NON-NLS-1$
Job(// $NON-NLS-1$
"Fetch Job") {
@Override
public IStatus run(IProgressMonitor monitor) {
boolean needsRefresh = false;
for (IArchiRepository repo : getRepositories(getRootFolder())) {
if (getControl().isDisposed()) {
return Status.OK_STATUS;
}
// If the user name and password are stored
SimpleCredentialsStorage scs = new SimpleCredentialsStorage(new File(repo.getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
try {
String userName = scs.getUsername();
String userPassword = scs.getPassword();
if (userName != null && userPassword != null) {
repo.fetchFromRemote(userName, userPassword, null, false);
needsRefresh = true;
}
} catch (IOException | GitAPIException ex) {
// silence is golden
}
}
if (needsRefresh) {
refreshInBackground();
}
if (!getControl().isDisposed()) {
// Schedule again in 20 seconds
schedule(20000);
}
return Status.OK_STATUS;
}
@Override
protected void canceling() {
/*
* Because the Git Fetch process doesn't respond to cancel requests we can't cancel it when it is running.
* So, if the user closes the app this job might be running. So we will wait for this job to finish
*/
int timeout = 0;
final int delay = 100;
try {
while (getState() == Job.RUNNING) {
Thread.sleep(delay);
timeout += delay;
if (timeout > 30000) {
// don't wait longer than this
break;
}
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
};
fetchJob.schedule(1000);
}
use of org.archicontribs.modelrepository.grafico.IArchiRepository in project archi-modelrepository-plugin by archi-contribs.
the class ModelRepositoryView method updateStatusBar.
protected void updateStatusBar(ISelection selection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof IArchiRepository) {
IArchiRepository repo = (IArchiRepository) obj;
ModelRepoTreeLabelProvider labelProvider = (ModelRepoTreeLabelProvider) getViewer().getLabelProvider();
Image image = labelProvider.getImage(repo);
// $NON-NLS-1$
String text = repo.getName() + " - " + labelProvider.getStatusText(repo);
getViewSite().getActionBars().getStatusLineManager().setMessage(image, text);
} else {
// $NON-NLS-1$
getViewSite().getActionBars().getStatusLineManager().setMessage(null, "");
}
}
Aggregations