Java Code Examples for org.eclipse.swt.custom.CTabItem#setData()

The following examples show how to use org.eclipse.swt.custom.CTabItem#setData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CTabFolderStackPresentation.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
@Override
public void addPart(final IPresentablePart newPart, Object cookie)
{
    ignoreSelection = true;
    final CTabItem item = new CTabItem(tabFolder,SWT.NONE);
    ignoreSelection = false;
    item.setData(DATAKEY_PART,newPart);
    
    updateItem(newPart);
    
    newPart.addPropertyListener(new IPropertyListener()
    {        
        public void propertyChanged(Object source, int propId)
        {
            updateItem(newPart);
        }        
    });
}
 
Example 2
Source File: BrowserViewPart.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void refreshTabContent() {
	if (browserTabs != null && browserTabs.length != 0) {
		for (BrowserTab tab : browserTabs) {
			tab.close();
		}
	}
	browserTabs = new BrowserTab[urls.size()];
	for (int i = 0; i < urls.size(); i++) {
		SearchEntry searchEntry = urls.get(i);
		browserTabs[i] = new BrowserTab(searchEntry);
		CTabItem item = new CTabItem(tabFolder, SWT.NONE);
		browserTabs[i].setItem(item);
		item.setText(searchEntry.getSearchName().replaceAll("&", "&&"));
		item.setControl(browserTabs[i].createTabFolderPage(tabFolder));
		item.setData(browserTabs[i]);
		Image image = getImage(searchEntry.getSearchUrl());
		if (null != image) {
			item.setImage(image);
		}
		browserTabs[i].searchKeyWord(keyWordForSearch.getText());
	}
	tabFolder.setSelection(0);
	tabFolder.layout();
}
 
Example 3
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
private void handleRenameItem(TreeItem item, String newName) {
	if (item.getData() instanceof SymitarFile) {
		// Set SymitarFile name
		if (((SymitarFile) item.getData()).saveName(newName))
			item.setText(newName); // Set name in tree

		// Now, set name in any open tabs
		for (CTabItem c : mainfolder.getItems())
			if (c.getData("file") == item.getData()) // Be sure it's the
				// exact same
				// instance, like it
				// should be
			{
				c.setText(newName);
				if (c.getControl() instanceof EditorComposite) {
					c.setData("modified", false);
					((EditorComposite) c.getControl()).updateModified();
				}
			}
	}

	if (item.getData() instanceof Project) {
		((Project) item.getData()).setName(newName);
		item.setText(newName);
	}
}
 
Example 4
Source File: EditorComposite.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
public void updateModified(){
	CTabFolder folder = (CTabFolder)getParent();
	Object loc;

	if( file.isLocal())
		loc = file.getDir();
	else
		loc = file.getSym();

	for( CTabItem cur : folder.getItems())
		if( cur.getData("file") != null && ((SymitarFile)cur.getData("file")).equals(file) && cur.getData("loc").equals(loc)  )
			if( modified && ( cur.getData("modified") == null || !((Boolean)cur.getData("modified")))){
				cur.setData("modified", true);
				cur.setText(cur.getText() + " *");
			}
			else if( !modified && ( cur.getData("modified") == null || ((Boolean)cur.getData("modified")))){
				cur.setData("modified", false);
				cur.setText(cur.getText().substring(0,cur.getText().length() - 2));
			}
}
 
Example 5
Source File: KGPrintView.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
CTabItem addItem(final String template, final String title, final Kontakt adressat){
	CTabItem ret = new CTabItem(ctab, SWT.NONE);
	text = new TextContainer(getViewSite());
	ret.setControl(text.getPlugin().createContainer(ctab, new ICallback() {
		public void save(){}
		
		public boolean saveAs(){
			return false;
		}
		
	}));
	Brief actBrief =
		text.createFromTemplateName(Konsultation.getAktuelleKons(), template, Brief.UNKNOWN,
			adressat, Messages.KGPrintView_EMR); //$NON-NLS-1$
	ret.setData("brief", actBrief); //$NON-NLS-1$
	ret.setData("text", text); //$NON-NLS-1$
	ret.setText(title);
	return ret;
}
 
Example 6
Source File: TemplatePrintView.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
CTabItem addItem(final String template, final String title, final Kontakt adressat){
	CTabItem ret = new CTabItem(ctab, SWT.NONE);
	text = new TextContainer(getViewSite());
	ret.setControl(text.getPlugin().createContainer(ctab, new ICallback() {
		public void save(){}
		
		public boolean saveAs(){
			return false;
		}
		
	}));
	Brief actBrief =
		text.createFromTemplateName(Konsultation.getAktuelleKons(), template, Brief.UNKNOWN,
			adressat, title);
	ret.setData(KEY_BRIEF, actBrief);
	ret.setData(KEY_TEXT, text);
	ret.setText(title);
	return ret;
}
 
Example 7
Source File: CodeSelectorFactory.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * add all available tabs as they occur (independent from any user settings)
 * 
 * @param list
 *            list of tabs to add
 * @param ctab
 *            parent
 */
private static void addAllTabs(java.util.List<IConfigurationElement> list, CTabFolder ctab,
	String point){
	ITEMS_TO_SHOW_IN_MFU_LIST = CoreHub.userCfg.get(Preferences.USR_MFU_LIST_SIZE, 15);
	ctab.setSimple(false);
	
	//add favorites tab first
	if (point.equals(ExtensionPointConstantsUi.VERRECHNUNGSCODE)) {
		new FavoritenCTabItem(ctab, SWT.None);
	}
	
	if (list != null) {
		for (IConfigurationElement ic : list) {
			Optional<CodeSystemDescription> systemDescription = CodeSystemDescription.of(ic);
			if (systemDescription.isPresent()) {
				CTabItem tabItem = new CTabItem(ctab, SWT.NONE);
				tabItem.setText(systemDescription.get().getCodeSystemName());
				tabItem.setData(systemDescription.get());
			}
		}
	}
}
 
Example 8
Source File: TabFolderReorder.java    From hop with Apache License 2.0 5 votes vote down vote up
private void moveTabs( CTabFolder folder, DropTargetEvent event ) {
  Point point = folder.toControl( folder.getDisplay().getCursorLocation() );
  CTabItem item = folder.getItem( new Point( point.x, point.y ) );
  if ( item != null && dragItem != null ) {
    Control dragControl = dragItem.getControl();
    String dragText = dragItem.getText();
    Image dragImage = dragItem.getImage();
    String dragToolTip = dragItem.getToolTipText();
    boolean dragShowClose = dragItem.getShowClose();
    Object dragData = dragItem.getData();

    dragItem.setText( item.getText() );
    dragItem.setImage( item.getImage() );
    dragItem.setToolTipText( item.getToolTipText() );
    dragItem.setData( item.getData() );
    dragItem.setShowClose( item.getShowClose() );
    dragItem.setControl( item.getControl() );

    item.setText( dragText );
    item.setImage( dragImage );
    item.setToolTipText( dragToolTip );
    item.setData( dragData );
    item.setShowClose( dragShowClose );
    item.setControl( dragControl );

    folder.setSelection( item );
  }
}
 
Example 9
Source File: KGPrintView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void useItem(int idx, String template, Kontakt adressat){
	CTabItem item = ctab.getItem(idx);
	Brief brief = (Brief) item.getData("brief"); //$NON-NLS-1$
	TextContainer text = (TextContainer) item.getData("text"); //$NON-NLS-1$
	text.saveBrief(brief, Brief.UNKNOWN);
	String betreff = brief.getBetreff();
	brief.delete();
	if (template != null) {
		Brief actBrief =
			text.createFromTemplateName(Konsultation.getAktuelleKons(), template,
				Brief.UNKNOWN, adressat, betreff);
		item.setData("brief", actBrief); //$NON-NLS-1$
	}
}
 
Example 10
Source File: TemplatePrintView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void useItem(int idx, String template, Kontakt adressat){
	CTabItem item = ctab.getItem(idx);
	if (!item.isDisposed()) {
		Brief brief = (Brief) item.getData(KEY_BRIEF);
		TextContainer text = (TextContainer) item.getData(KEY_TEXT);
		text.saveBrief(brief, Brief.UNKNOWN);
		String betreff = brief.getBetreff();
		brief.delete();
		if (template != null) {
			Brief actBrief = text.createFromTemplateName(Konsultation.getAktuelleKons(),
				template, Brief.UNKNOWN, adressat, betreff);
			item.setData(KEY_BRIEF, actBrief);
		}
	}
}
 
Example 11
Source File: CodeDetailView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void addPagesFor(String point){
	List<IConfigurationElement> list = Extensions.getExtensions(point);
	for (IConfigurationElement ce : list) {
		try {
			if ("Artikel".equals(ce.getName())) { //$NON-NLS-1$
				continue;
			}
			IDetailDisplay detailDisplay =
				(IDetailDisplay) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_CDD);
			CodeSelectorFactory codeSelector =
				(CodeSelectorFactory) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_CSF);
			String a = ce.getAttribute(ExtensionPointConstantsUi.VERRECHNUNGSCODE_IMPC);
			ImporterPage ip = null;
			if (a != null) {
				ip = (ImporterPage) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_IMPC);
				if (ip != null) {
					importers.put(detailDisplay.getTitle(), ip);
				}
			}
			MasterDetailsPage page = new MasterDetailsPage(ctab, codeSelector, detailDisplay);
			CTabItem ct = new CTabItem(ctab, SWT.NONE);
			ct.setText(detailDisplay.getTitle());
			ct.setControl(page);
			ct.setData(detailDisplay);
			
			CoreUiUtil.injectServicesWithContext(codeSelector);
			CoreUiUtil.injectServicesWithContext(detailDisplay);
		} catch (Exception ex) {
			LoggerFactory.getLogger(getClass()).error("Error creating pages", ex);
			ElexisStatus status =
				new ElexisStatus(ElexisStatus.WARNING, Hub.PLUGIN_ID, ElexisStatus.CODE_NONE,
					"Fehler beim Initialisieren von " + ce.getName(), ex,
					ElexisStatus.LOG_WARNINGS);
			StatusManager.getManager().handle(status, StatusManager.SHOW);
		}
	}
}
 
Example 12
Source File: TabbedMDI_Ren.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Point computeSize(int part, int state, GC gc, int wHint,
		int hHint) {
	gc.setAntialias(SWT.ON);
	Point pt = super.computeSize(part, state, gc, wHint, hHint);
	if (tabFolder.isDisposed()) {
		return pt;
	}

	if (part < 0 || part >= tabFolder.getItemCount()) {
		return pt;
	}

	CTabItem item = tabFolder.getItem(part);
	if (item == null) {
		return pt;
	}

	TabbedEntry entry = mdi.getEntryFromTabItem(item);
	if (entry == null) {
		return pt;
	}

	int ourWidth = 0;

	ViewTitleInfo viewTitleInfo = entry.getViewTitleInfo();
	if (viewTitleInfo != null) {
		Object titleRight = viewTitleInfo.getTitleInfoProperty(
				ViewTitleInfo.TITLE_INDICATOR_TEXT);
		if (titleRight != null) {
			String textIndicator = titleRight.toString();
			item.setData("textIndicator", textIndicator);
			Point size = gc.textExtent(textIndicator, 0);
			ourWidth += size.x + (PADDING_BUBBLE_X * 2) + PADDING_INDICATOR_X1;
		} else {
			item.setData("textIndicator", null);
		}
	} else {
		item.setData("textIndicator", null);
	}

	boolean showUnselectedClose = tabFolder.getUnselectedCloseVisible();
	boolean selected = (state & SWT.SELECTED) != 0;
	boolean parentHasClose = (tabFolder.getStyle() & SWT.CLOSE) != 0;
	boolean showingClose = (parentHasClose || item.getShowClose())
			&& (showUnselectedClose || selected);

	List<MdiEntryVitalityImageSWT> vitalityImages = entry.getVitalityImages();
	boolean first = true;
	for (MdiEntryVitalityImageSWT vitalityImage : vitalityImages) {
		if (vitalityImage == null || !vitalityImage.isVisible()
				|| vitalityImage.getAlignment() != SWT.RIGHT
				|| vitalityImage.getShowOutsideOfEntry()) {
			continue;
		}
		
		if (!selected && vitalityImage.getShowOnlyOnSelection()) {
			continue;
		}

		Image image = vitalityImage.getImage();
		if (com.biglybt.ui.swt.imageloader.ImageLoader.isRealImage(image)) {
			ourWidth += image.getBounds().width;
			if (first && !vitalityImage.getAlwaysLast()) {
				first = false;
			}
			ourWidth += PADDING_INDICATOR_X1;
		}
	}
	
	if (!selected) {
		ourWidth += PADDING_INDICATOR_AND_CLOSE;
	}

	pt.x += ourWidth;

	return pt;
}
 
Example 13
Source File: ModelEditor.java    From tlaplus with MIT License 4 votes vote down vote up
protected void addPages()
 {
     // TLCUIActivator.getDefault().logDebug("entering ModelEditor#addPages()");
     try
     {
         // This code moves the tabs to the top of the page.
         // This makes them more obvious to the user.
     	final CTabFolder tabFolder = (CTabFolder)getContainer();
     	tabFolder.setTabPosition(SWT.TOP);
     	tabFolder.addCTabFolder2Listener(listener);

for (int i = 0; i < pagesToAdd.length; i++) {
             addPage(pagesToAdd[i]);
             // initialize the page
             // this means the content will be created
             // the data will be loaded
             // the refresh method will update the UI state
             // the dirty listeners will be activated
             if (pagesToAdd[i].getPartControl() == null)
             {
                 pagesToAdd[i].createPartControl(tabFolder);
                 setControl(i, pagesToAdd[i].getPartControl());
                 pagesToAdd[i].getPartControl().setMenu(tabFolder.getMenu());
             }
             
             final CTabItem item = tabFolder.getItem(i);
             // we have to do this to allow our superclass' getEditor(int) to work correctly since we don't
             //		add the page via addPage(IEditorPart,IEditorInput)
             item.setData(pagesToAdd[i]);
             if (pagesToAdd[i] instanceof Closeable) {
     			item.setShowClose(true);
     			
     			indexCloseableMap.put(new Integer(i), (Closeable)pagesToAdd[i]);
             }
         }

         // at this point everything is activated and initialized.
         // run the validation
         UIHelper.runUIAsync(validateRunable);

         
         final ModuleNode rootModule = SemanticHelper.getRootModuleNode();
if ((rootModule != null) && (rootModule.getVariableDecls().length == 0)
		&& (rootModule.getConstantDecls().length == 0)) {
         	addOrShowResultsPage();
         }
         
         if (model.hasStateGraphDump()) {
         	addOrUpdateStateGraphEditor(model.getStateGraphDump());
         }
     } catch (CoreException e)
     {
         TLCUIActivator.getDefault().logError("Error initializing editor", e);
     }

     // TLCUIActivator.getDefault().logDebug("leaving ModelEditor#addPages()");
 }
 
Example 14
Source File: WizardBaseDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void initializeBounds( )
{
	// Set shell properties
	getShell( ).setText( wizardTitle );
	setTitle( wizardTitle );
	if ( imgShell != null )
	{
		getShell( ).setImage( imgShell );
	}
	getShell( ).addControlListener( this );
	getShell( ).addDisposeListener( this );

	// Add each task to container
	String[] allTasks = TasksManager.instance( )
			.getTasksForWizard( this.wizardBase.sWizardID );
	for ( int i = 0; i < allTasks.length; i++ )
	{
		// Create the blank tab item.
		CTabItem item = new CTabItem( getTabContainer( ), SWT.NONE );
		item.setImage( TasksManager.instance( )
				.getTask( allTasks[i] )
				.getImage( ) );
		item.setText( TasksManager.instance( )
				.getTask( allTasks[i] )
				.getTitle( ) );
		item.setData( allTasks[i] );
	}

	if ( tmpTopTaskId != null )
	{
		int taskIndex = this.wizardBase.vTaskIDs.indexOf( tmpTopTaskId );
		cmpTaskContainer.setSelection( taskIndex );
	}

	// Open current task
	if ( this.wizardBase.getCurrentTask( ) != null )
	{
		this.wizardBase.getCurrentTask( ).setContext( this.wizardBase.context );

		// Do not pack wizard since the bound has been calculated by
		// jface
		this.wizardBase.packNeeded = false;
		this.wizardBase.switchTo( this.wizardBase.sCurrentActiveTask );
		this.wizardBase.packNeeded = true;
	}

	super.initializeBounds( );
}
 
Example 15
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 4 votes vote down vote up
public Object openFile(final SymitarFile file) {
	boolean found = false;
	Composite editor;
	Object loc;

	if (file.isLocal())
		loc = file.getDir();
	else
		loc = file.getSym();

	for (CTabItem c : mainfolder.getItems()) {
		if (c.getData("file") != null && c.getData("file").equals(file) && c.getData("loc") != null && c.getData("loc").equals(loc)) {
			setMainFolderSelection(c);
			found = true;
			return c.getControl();
		}
	}

	if (!found) {
		CTabItem item = new CTabItem(mainfolder, SWT.CLOSE); 
		item.setText(file.getName());
		// item.setToolTipText(file.getName()); // only use this if we are shrinking tabs
		item.setImage(getFileImage(file));
		item.setData("file", file);
		item.setData("loc", loc);

		if (file.getType() == FileType.REPORT)
			editor = new ReportComposite(mainfolder, item, file);
		else {
			editor = new EditorComposite(mainfolder, item, file /*
			 * ,save,
			 * install,
			 * print,
			 * run
			 */);
			//EditorCompositeList.add((EditorComposite)editor);
		}

		// If anything goes wrong creating the Editor, we want to fail here
		// It will dispose of the item to indicate this fault.
		if (item.isDisposed()) {
			MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
			dialog.setMessage("There has been an error loading this file, the filename is probably too long");
			dialog.setText("Error");
			dialog.open();

			return null;
		}

		mainfolder.setSelection(item);
		item.setControl(editor);
		setMainFolderSelection(item);
		mainfolder.notifyListeners(SWT.Selection, new Event());
		


		//When we are closing, we must dispose the control in the CTabItem, otherwise we leak swt objects
		item.addDisposeListener(new DisposeListener(){
			public void widgetDisposed(DisposeEvent e) {
				if(((CTabItem)e.widget).getControl() != null)
					((CTabItem)e.widget).getControl().dispose();
			}
		});

		if (file.getType() != FileType.REPGEN || file.isLocal())
			install.setEnabled(false);
		else
			install.setEnabled(true);

		if (file.getType() != FileType.REPGEN || file.isLocal())
			run.setEnabled(false);
		else
			run.setEnabled(true);

		savetb.setEnabled(true);

		if ((file.getType() == FileType.REPGEN)||(file.getType() == FileType.LETTER)||(file.getType() == FileType.HELP))
			hltoggle.setEnabled(true);

		if (mainfolder.getSelection().getControl() instanceof EditorComposite){
			if(((EditorComposite)mainfolder.getSelection().getControl()).getHighlight()){
				hltoggle.setImage(RepDevMain.smallHighlight);
			}else{
				hltoggle.setImage(RepDevMain.smallHighlightGrey);
			}
		}
		// Attach find/replace shell here as well (in addition to folder
		// listener)
		findReplaceShell.attach(((EditorComposite) mainfolder.getSelection().getControl()).getStyledText(), true);

		if (!Config.getRecentFiles().contains(file))
			Config.getRecentFiles().add(0, file);

		if (Config.getRecentFiles().size() > MAX_RECENTS)
			Config.getRecentFiles().remove(Config.getRecentFiles().size() - 1);
		return editor;
	}

	return null;
}
 
Example 16
Source File: CodeDetailView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private void addUserSpecifiedPages(String settings){
	String[] userSettings = settings.split(",");
	Map<Integer, IConfigurationElement> iceMap = new TreeMap<Integer, IConfigurationElement>();
	
	iceMap = collectNeededPages(ExtensionPointConstantsUi.DIAGNOSECODE, userSettings, iceMap);
	iceMap =
		collectNeededPages(ExtensionPointConstantsUi.VERRECHNUNGSCODE, userSettings, iceMap);
	iceMap = collectNeededPages(ExtensionPointConstantsUi.GENERICCODE, userSettings, iceMap);
	
	// add favorites tab if settings desire it
	for (int i = 0; i < userSettings.length; i++) {
		if (userSettings[i].equals("Favoriten")) {
			iceMap.put(i, null);
		}
	}
	
	for (Integer key : iceMap.keySet()) {
		IConfigurationElement ce = iceMap.get(key);
		if (ce == null) {
			new FavoritenCTabItem(ctab, SWT.None);
			continue;
		}
		
		try {
			IDetailDisplay detailDisplay =
				(IDetailDisplay) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_CDD);
			CodeSelectorFactory codeSelector =
				(CodeSelectorFactory) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_CSF);
			String a = ce.getAttribute(ExtensionPointConstantsUi.VERRECHNUNGSCODE_IMPC);
			ImporterPage ip = null;
			if (a != null) {
				ip = (ImporterPage) ce.createExecutableExtension(ExtensionPointConstantsUi.VERRECHNUNGSCODE_IMPC);
				if (ip != null) {
					importers.put(detailDisplay.getTitle(), ip);
				}
			}
			
			MasterDetailsPage page = new MasterDetailsPage(ctab, codeSelector, detailDisplay);
			CTabItem ct = new CTabItem(ctab, SWT.NONE);
			ct.setText(detailDisplay.getTitle());
			ct.setControl(page);
			ct.setData(detailDisplay);
			
			CoreUiUtil.injectServices(codeSelector);
			CoreUiUtil.injectServices(detailDisplay);
		} catch (Exception ex) {
			LoggerFactory.getLogger(getClass()).error("Error creating pages", ex);
			ElexisStatus status =
				new ElexisStatus(ElexisStatus.WARNING, Hub.PLUGIN_ID, ElexisStatus.CODE_NONE,
					"Fehler beim Initialisieren von " + ce.getName(), ex,
					ElexisStatus.LOG_WARNINGS);
			StatusManager.getManager().handle(status, StatusManager.SHOW);
		}
	}
}