@Override
  public void initialize(ISynchronizePageConfiguration configuration) {
    super.initialize(configuration);
    final Viewer viewer = configuration.getPage().getViewer();
    if (viewer instanceof AbstractTreeViewer) {

      expandAllAction = new ExpandAllAction((AbstractTreeViewer) viewer);
      Utils.initAction(expandAllAction, "action.expandAll."); // $NON-NLS-1$

      collapseAll =
          new Action() {
            @Override
            public void run() {
              if (viewer.getControl().isDisposed() || !(viewer instanceof AbstractTreeViewer))
                return;
              viewer.getControl().setRedraw(false);
              ((AbstractTreeViewer) viewer)
                  .collapseToLevel(viewer.getInput(), AbstractTreeViewer.ALL_LEVELS);
              viewer.getControl().setRedraw(true);
            }
          };
      Utils.initAction(collapseAll, "action.collapseAll."); // $NON-NLS-1$

      ICompareNavigator nav =
          (ICompareNavigator) configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
      if (nav != null) {
        gotoNext = new NavigateAction(configuration, true /*next*/);
        gotoPrevious = new NavigateAction(configuration, false /*previous*/);
      }
    }
  }
 public void runViewUpdate(final Runnable runnable, final boolean preserveExpansion) {
   if (Utils.canUpdateViewer(getViewer()) || isPerformingBackgroundUpdate()) {
     internalRunViewUpdate(runnable, preserveExpansion);
   } else {
     if (Thread.currentThread() != getEventHandlerJob().getThread()) {
       // Run view update should only be called from the UI thread or
       // the update handler thread.
       // We will log the problem for now and make it an assert later
       TeamUIPlugin.log(
           IStatus.WARNING,
           "View update invoked from invalid thread",
           new TeamException(
               "View update invoked from invalid thread")); //$NON-NLS-1$ //$NON-NLS-2$
     }
     final Control ctrl = getViewer().getControl();
     if (ctrl != null && !ctrl.isDisposed()) {
       ctrl.getDisplay()
           .syncExec(
               new Runnable() {
                 public void run() {
                   if (!ctrl.isDisposed()) {
                     BusyIndicator.showWhile(
                         ctrl.getDisplay(),
                         new Runnable() {
                           public void run() {
                             internalRunViewUpdate(runnable, preserveExpansion);
                           }
                         });
                   }
                 }
               });
     }
   }
 }
 /**
  * Forces the viewer to update the labels for queued elemens whose label has changed during this
  * round of changes. This method should only be invoked in the UI thread.
  */
 protected void firePendingLabelUpdates() {
   if (!Utils.canUpdateViewer(getViewer())) return;
   try {
     Object[] updates = pendingLabelUpdates.toArray(new Object[pendingLabelUpdates.size()]);
     updateLabels(updates);
   } finally {
     pendingLabelUpdates.clear();
   }
 }
 @Override
 public void run() {
   if (status != null && !status.isOK()) {
     ErrorDialog.openError(
         Utils.getShell(null), null, TeamUIMessages.RefreshSubscriberJob_3, status);
   } else if (gotoAction != null) {
     gotoAction.run();
   }
 }
  /*
   * Method that can be called from the UI thread to update the view model.
   */
  private void internalRunViewUpdate(final Runnable runnable, boolean preserveExpansion) {
    StructuredViewer viewer = getViewer();
    IResource[] expanded = null;
    IResource[] selected = null;
    try {
      if (Utils.canUpdateViewer(viewer)) {
        viewer.getControl().setRedraw(false);
        if (preserveExpansion) {
          expanded = provider.getExpandedResources();
          selected = provider.getSelectedResources();
        }
        if (viewer instanceof AbstractTreeViewer && additionsMap == null)
          additionsMap = new HashMap();
      }
      runnable.run();
    } finally {
      if (Utils.canUpdateViewer(viewer)) {
        try {
          if (additionsMap != null && !additionsMap.isEmpty() && Utils.canUpdateViewer(viewer)) {
            for (Iterator iter = additionsMap.keySet().iterator(); iter.hasNext(); ) {
              ISynchronizeModelElement parent = (ISynchronizeModelElement) iter.next();
              if (Policy.DEBUG_SYNC_MODELS) {
                System.out.println("Adding child view items of " + parent.getName()); // $NON-NLS-1$
              }
              Set toAdd = (Set) additionsMap.get(parent);
              ((AbstractTreeViewer) viewer).add(parent, toAdd.toArray(new Object[toAdd.size()]));
            }
            additionsMap = null;
          }
          if (expanded != null) {
            provider.expandResources(expanded);
          }
          if (selected != null) {
            provider.selectResources(selected);
          }
        } finally {
          viewer.getControl().setRedraw(true);
        }
      }
    }

    ISynchronizeModelElement root = provider.getModelRoot();
    if (root instanceof SynchronizeModelElement) ((SynchronizeModelElement) root).fireChanges();
  }
 @Override
 public String getToolTipText() {
   if (status != null && !status.isOK()) {
     return status.getMessage();
   }
   if (gotoAction != null) {
     return gotoAction.getToolTipText();
   }
   return Utils.shortenText(
       SynchronizeView.MAX_NAME_LENGTH, RefreshParticipantJob.this.getName());
 }
 /** Refresh the subtree associated with this model. */
 protected void refresh() {
   Utils.syncExec(
       new Runnable() {
         public void run() {
           TreeViewer treeViewer = ((TreeViewer) getViewer());
           // TODO: Need to know if the model root is present in order to refresh properly
           if (empty) treeViewer.refresh();
           else treeViewer.refresh(getModelProvider());
         }
       },
       getViewer().getControl());
 }
 private String getContentIdentifier(ITypedElement element) {
   if (element instanceof FileRevisionTypedElement) {
     FileRevisionTypedElement fileRevisionElement = (FileRevisionTypedElement) element;
     Object fileObject = fileRevisionElement.getFileRevision();
     if (fileObject instanceof LocalFileRevision) {
       try {
         IStorage storage = ((LocalFileRevision) fileObject).getStorage(new NullProgressMonitor());
         if (Utils.getAdapter(storage, IFileState.class) != null) {
           // local revision
           return Messages.GitCompareFileRevisionEditorInput_0;
         } else if (Utils.getAdapter(storage, IFile.class) != null) {
           // current revision
           return Messages.GitCompareFileRevisionEditorInput_1;
         }
       } catch (CoreException e) {
         GitUIPlugin.logError(
             Messages.GitCompareFileRevisionEditorInput_ProblemGettingContent_Error, e);
       }
     } else {
       return fileRevisionElement.getContentIdentifier();
     }
   }
   return Messages.GitCompareFileRevisionEditorInput_2;
 }
 /* (non-Javadoc)
  * @see org.eclipse.team.internal.core.BackgroundEventHandler#doDispatchEvents(org.eclipse.core.runtime.IProgressMonitor)
  */
 protected boolean doDispatchEvents(IProgressMonitor monitor) throws TeamException {
   // Fire label changed
   dispatchEarly = false;
   if (pendingLabelUpdates.isEmpty()) {
     return false;
   } else {
     Utils.asyncExec(
         new Runnable() {
           public void run() {
             firePendingLabelUpdates();
           }
         },
         getViewer());
     return true;
   }
 }
 /**
  * Return whether the given element has children in the given scope. By default, true is returned
  * if the given element contains any elements in the scope or if any of the elements in the scope
  * contain the given element and the delegate provider returns children for the element. The
  * {@link ResourceMapping#contains(ResourceMapping)} is used to test for containment. Subclasses
  * may override to provide a more efficient implementation.
  *
  * @param scope the scope
  * @param element the element
  * @return whether the given element has children in the given scope
  */
 protected boolean hasChildrenInScope(ISynchronizationScope scope, Object element) {
   ResourceMapping mapping = Utils.getResourceMapping(internalGetElement(element));
   if (mapping != null) {
     ResourceMapping[] mappings = scope.getMappings(mapping.getModelProviderId());
     for (int i = 0; i < mappings.length; i++) {
       ResourceMapping sm = mappings[i];
       if (mapping.contains(sm)) {
         return true;
       }
       if (sm.contains(mapping)) {
         return getDelegateChildren(element).length > 0;
       }
     }
   }
   return false;
 }
  private Composite getErrorComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setBackground(getListBackgroundColor());
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.grabExcessVerticalSpace = true;
    composite.setLayoutData(data);

    Hyperlink link = new Hyperlink(composite, SWT.WRAP);
    link.setText(TeamUIMessages.ChangesSection_8);
    link.addHyperlinkListener(
        new HyperlinkAdapter() {
          public void linkActivated(HyperlinkEvent e) {
            showErrors();
          }
        });
    link.setBackground(getListBackgroundColor());
    link.setUnderlined(true);

    link = new Hyperlink(composite, SWT.WRAP);
    link.setText(TeamUIMessages.ChangesSection_9);
    link.addHyperlinkListener(
        new HyperlinkAdapter() {
          public void linkActivated(HyperlinkEvent e) {
            getPage().reset();
          }
        });
    link.setBackground(getListBackgroundColor());
    link.setUnderlined(true);

    createDescriptionLabel(
        composite,
        NLS.bind(
            TeamUIMessages.ChangesSection_10,
            new String[] {
              Utils.shortenText(
                  SynchronizeView.MAX_NAME_LENGTH, getConfiguration().getParticipant().getName())
            }));

    return composite;
  }
예제 #12
0
  public void createDefaultMenuItem(Menu menu, final IFileRevision revision) {
    final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
    menuItem.setSelection(Utils.getDefaultEditor(revision) == null);
    menuItem.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_DefaultEditorDescription);

    Listener listener =
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                if (menuItem.getSelection()) {
                  openEditor(Utils.getDefaultEditor(revision), false);
                }
                break;
            }
          }
        };

    menuItem.addListener(SWT.Selection, listener);
  }
예제 #13
0
 private void openInCompare(ITypedElement ancestor, ITypedElement left, ITypedElement right) {
   IWorkbenchPage workBenchPage = getTargetPage();
   CompareEditorInput input =
       new SaveablesCompareEditorInput(ancestor, left, right, workBenchPage);
   IEditorPart editor =
       Utils.findReusableCompareEditor(
           input, workBenchPage, new Class[] {CompareFileRevisionEditorInput.class});
   if (editor != null) {
     IEditorInput otherInput = editor.getEditorInput();
     if (otherInput.equals(input)) {
       // simply provide focus to editor
       workBenchPage.activate(editor);
     } else {
       // if editor is currently not open on that input either re-use
       // existing
       CompareUI.reuseCompareEditor(input, (IReusableEditor) editor);
       workBenchPage.activate(editor);
     }
   } else {
     CompareUI.openCompareEditor(input);
   }
 }
 /*
  * Forces the viewer to update the labels for the given elements
  */
 private void updateLabels(Object[] elements) {
   StructuredViewer tree = getViewer();
   if (Utils.canUpdateViewer(tree)) {
     tree.update(elements, null);
   }
 }
예제 #15
0
  public void fill(Menu menu, int index) {
    final IFileRevision fileRevision = getFileRevision();
    if (fileRevision == null) {
      return;
    }

    IEditorDescriptor defaultTextEditor =
        registry.findEditor("org.eclipse.ui.DefaultTextEditor"); // $NON-NLS-1$
    IEditorDescriptor preferredEditor = Utils.getDefaultEditor(fileRevision);

    Object[] editors = Utils.getEditors(fileRevision);
    Collections.sort(Arrays.asList(editors), comparer);
    boolean defaultFound = false;

    // Check that we don't add it twice. This is possible
    // if the same editor goes to two mappings.
    ArrayList alreadyMapped = new ArrayList();

    for (int i = 0; i < editors.length; i++) {
      IEditorDescriptor editor = (IEditorDescriptor) editors[i];
      if (!alreadyMapped.contains(editor)) {
        createMenuItem(menu, editor, preferredEditor);
        if (defaultTextEditor != null && editor.getId().equals(defaultTextEditor.getId())) {
          defaultFound = true;
        }
        alreadyMapped.add(editor);
      }
    }

    // Only add a separator if there is something to separate
    if (editors.length > 0) {
      new MenuItem(menu, SWT.SEPARATOR);
    }

    // Add default editor. Check it if it is saved as the preference.
    if (!defaultFound && defaultTextEditor != null) {
      createMenuItem(menu, defaultTextEditor, preferredEditor);
    }

    // TODO : We might perhaps enable inplace and system external editors menu items
    /*// Add system editor
    IEditorDescriptor descriptor = registry
    		.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
    final MenuItem systemEditorMenuItem = createMenuItem(menu, descriptor,
    		preferredEditor);
    systemEditorMenuItem.setEnabled(false);

    // Add system in-place editor
    descriptor = registry
    		.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);

    final MenuItem inPlaceEditorMenuItem = (descriptor != null) ? createMenuItem(
    		menu, descriptor, preferredEditor)
    		: null;
    if (inPlaceEditorMenuItem != null)
    	inPlaceEditorMenuItem.setEnabled(false);

    Job job = new Job("updateOpenWithMenu") { //$NON-NLS-1$
    	protected IStatus run(IProgressMonitor monitor) {
    		try {
    			final boolean isFile = fileRevision.getStorage(monitor) instanceof IFile;
    			Display.getDefault().asyncExec(new Runnable() {
    				public void run() {
    					if (inPlaceEditorMenuItem != null
    							&& !inPlaceEditorMenuItem.isDisposed())
    						inPlaceEditorMenuItem.setEnabled(isFile);
    					if (!systemEditorMenuItem.isDisposed())
    						systemEditorMenuItem.setEnabled(isFile);
    				}
    			});
    			return Status.OK_STATUS;
    		} catch (CoreException e) {
    			return new Status(IStatus.WARNING, TeamUIPlugin.ID, null, e);
    		}
    	};
    };
    job.setSystem(true);
    job.schedule();*/

    createDefaultMenuItem(menu, fileRevision);

    // add Other... menu item
    createOtherMenuItem(menu);
  }
예제 #16
0
 protected IResource getResource(Object obj) {
   IResource[] resources = Utils.getResources(new Object[] {obj});
   return resources.length == 1 ? resources[0] : null;
 }