Search in sources :

Example 1 with IArchiRepository

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();
        }
    }
}
Also used : IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IOException(java.io.IOException)

Example 2 with IArchiRepository

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());
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IOException(java.io.IOException)

Example 3 with IArchiRepository

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;
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) ArchiRepository(org.archicontribs.modelrepository.grafico.ArchiRepository) IArchimateModel(com.archimatetool.model.IArchimateModel) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout)

Example 4 with IArchiRepository

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);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SimpleCredentialsStorage(org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 5 with IArchiRepository

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, "");
    }
}
Also used : IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModelRepoTreeLabelProvider(org.archicontribs.modelrepository.views.repositories.ModelRepositoryTreeViewer.ModelRepoTreeLabelProvider) Image(org.eclipse.swt.graphics.Image)

Aggregations

IArchiRepository (org.archicontribs.modelrepository.grafico.IArchiRepository)8 IOException (java.io.IOException)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IArchimateModel (com.archimatetool.model.IArchimateModel)2 ArchiRepository (org.archicontribs.modelrepository.grafico.ArchiRepository)2 UpdatingTableColumnLayout (com.archimatetool.editor.ui.components.UpdatingTableColumnLayout)1 File (java.io.File)1 SimpleCredentialsStorage (org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage)1 ModelRepoTreeLabelProvider (org.archicontribs.modelrepository.views.repositories.ModelRepositoryTreeViewer.ModelRepoTreeLabelProvider)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1 Image (org.eclipse.swt.graphics.Image)1